美文网首页
iOS 8.0 屏幕转向问题

iOS 8.0 屏幕转向问题

作者: PZcoder | 来源:发表于2017-03-30 10:17 被阅读9次

    问题描述: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的上述问题。

    相关文章

      网友评论

          本文标题:iOS 8.0 屏幕转向问题

          本文链接:https://www.haomeiwen.com/subject/peyuottx.html