美文网首页
app锁定屏幕方向,某一个界面支持屏幕旋转~

app锁定屏幕方向,某一个界面支持屏幕旋转~

作者: 某天天 | 来源:发表于2018-04-18 17:29 被阅读0次

    AppDelegate.h 加

    @property (nonatomic, assign) BOOL allowRotation;
    

    Appdelegate.m加

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
      if (self.allowRotation) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
      }
      return UIInterfaceOrientationMaskPortrait;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
      return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
      return UIInterfaceOrientationPortrait;
    }
    

    之后在需要支持屏幕旋转的界面的特定位置上添加代码:

    • 打开屏幕旋转:
      AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
      delegate.allowRotation = YES;
    
    • 关闭屏幕旋转:
      AppDelegate  *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
      delegate.allowRotation = NO;
    

    相关文章

      网友评论

          本文标题:app锁定屏幕方向,某一个界面支持屏幕旋转~

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