iOS6的目标定位应该是Autorotate

时间:2012-10-03 09:16:07

标签: cocoa ios6

我想根据目标方向允许旋转

[[UIDevice currentDevice] orientation] 

然而,上面的代码在shouldRotate中使用时保持当前(旧)方向,而不是目标方向

- (BOOL) shouldAutorotate {

    return YES;
}

3 个答案:

答案 0 :(得分: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
}

答案 1 :(得分:0)

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

这种方法可以帮到你。 toInterfaceOrientation保持目标方向。

答案 2 :(得分:-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