首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS7 - AutoRotate未被调用

iOS7 - AutoRotate未被调用
EN

Stack Overflow用户
提问于 2014-02-28 01:46:58
回答 1查看 115关注 0票数 0

队员们,

我正在做一个支持项目,我对iPhone有基本的了解。当我在设备中更改方向时,以下任何方法都不会在方向更改时被调用。

代码语言:javascript
复制
- (BOOL)shouldAutorotate {

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationPortrait) {
        // your code for portrait mode

    }

    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait;
    //return here which orientation you are going to support

}

我正在通过presentViewController推送屏幕,上面的方法在推送屏幕之前会被调用,但在推送屏幕之后和更改方向时没有任何变化。

此外,我尝试创建一个类别,如下所述,但我得到的viewController找不到错误,不确定我这里错过了什么…

在IOS7中,如果你使用UINavigationController,旋转处理的方式是不同的!

见UINavigationController,可以看出它是UIViewController的一个子类,那就是在他上面有列出的旋转处理方法;所以我们需要用UINavigationController也做旋转处理,

我的方法是向UINavigationController添加一个类别,这样做。

在类别中。M次写入

代码语言:javascript
复制
-(BOOL)shouldAutorotate {    
  return [[self.viewControllers lastObject] shouldAutorotate];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
}

任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

发布于 2014-02-28 01:55:06

对我来说,其他两个函数也是有效的,但您可以尝试使用下面的委托

来自Apple Docs:

在用户界面开始rotating.

  • (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation之前发送到视图控制器的

持续时间:(NSTimeInterval)持续时间

在用户界面旋转后发送到视图控制器:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22076305

复制
相关文章

相似问题

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