首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >iOS 6 shouldAutorotate:未被调用

iOS 6 shouldAutorotate:未被调用
EN

Stack Overflow用户
提问于 2012-10-08 12:20:01
回答 4查看 48.7K关注 0票数 48

我一直在互联网上寻找解决方案,但一无所获。我正在尝试使我的iOS 5应用程序与iOS 6兼容。我不能让迎新的东西正常工作。我无法检测到何时会发生旋转。下面是我正在尝试的代码:

代码语言:javascript
复制
- (BOOL)shouldAutorotate {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

新的supportedInterfaceOrientation:方法可以很好地调用。但是,shouldAutorotate方法不会触发。我需要在旋转时进行一些图像交换,但我无法获得任何旋转即将发生的迹象。

提前谢谢。

EN

回答 4

Stack Overflow用户

发布于 2013-05-08 16:27:34

当使用UINavigationController作为应用程序的基础时,我使用以下子类为我提供了灵活性,允许最顶层的子视图控制器决定旋转。

代码语言:javascript
复制
@interface RotationAwareNavigationController : UINavigationController

@end

@implementation RotationAwareNavigationController

-(NSUInteger)supportedInterfaceOrientations {
    UIViewController *top = self.topViewController;
    return top.supportedInterfaceOrientations;
}

-(BOOL)shouldAutorotate {
    UIViewController *top = self.topViewController;
    return [top shouldAutorotate];
}

@end
票数 45
EN

Stack Overflow用户

发布于 2014-04-20 21:54:44

我使用的是iOS 7,但我相信我的案例可能会对其他人有所帮助。

我有一个以UITabBarController为根的深层视图控制器层次结构。保证调用shouldAutorotate的唯一位置是在UITabBarController内部。因此,我简单地将UITabBarController子类化,并将旋转控制逻辑放入shouldAutorotate方法中。

票数 1
EN

Stack Overflow用户

发布于 2013-06-13 07:27:21

这就是我要做的

如果要检查哪个是当前方向,请将此行添加到viewconrtoller.m文件中

代码语言:javascript
复制
 #define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown

然后在你想要检查方向的地方,像下面这样写条件

代码语言:javascript
复制
- (void)viewDidLoad
{

        if(isPortrait)
        {
            //portrait mode....

            NSLog(@"its in IsPotraitMode");
        }
        else
        {
            //landscape mode....
            NSLog(@"its in IsLandscapeMode");
        }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12775265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档