2

i want to allow the should rotate, based on the target orientation

[[UIDevice currentDevice] orientation] 

however the code above, when used in shouldRotate holds the current (old) orientation, not the target orientation

- (BOOL) shouldAutorotate {

    return YES;
}
4

3 回答 3

0
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

这种方法应该为您解决问题。toInterfaceOrientation 保存目标方向。

于 2012-10-12T14:01:56.310 回答
0

好吧,我想通了。始终在 shouldAutorotate 中返回 YES,然后执行以下操作:

- (NSUInteger)supportedInterfaceOrientations
{
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
        // Allow if you can
    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
        // Allow if you can
    }
    // so on
}
于 2012-10-12T11:21:05.630 回答
-1

除了返回是

-(BOOL)shouldAutorotate
{
return YES;
}

你必须实施

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

可用的不同面具是:

UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown

您可能还想看:

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

于 2012-10-03T09:54:14.703 回答