iOS 8.0 屏幕转向问题

问题描述:iOS8.0系统中,A页面推出B页面(横屏展示),B页面关闭后,A页面转向。

解决办法(亲测有效):

步骤1.在AppDelegate.h中设置一个标识(isInterface),在AppDelegate.m中的此方法中判断标识,并返回UIInterfaceOrientationMaskPortrait。

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if(self.isInterface)
        return UIInterfaceOrientationMaskAll;
    else
        return UIInterfaceOrientationMaskPortrait;
}

步骤2.在B页面(横屏展示的页面)的返回方法中给改变isInterface的值。
注意:一定要写在dismiss方法之前才有效。

- (IBAction)dismissAction:(UIButton *)sender
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    app.isInterface = NO;
    
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

步骤3.其他页面设置(不需要横屏的页面)
注:貌似不写这几个方法也可以。

-(BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

做好以上3步即可解决iOS8.0的上述问题。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容