zoukankan      html  css  js  c++  java
  • object-c中实现特定一个或者多个页面横竖屏,其他界面保持竖屏显示。

    1.首先设置项目支持的屏幕方向。info.plist设置(自行设置)

    2.写一个子类CusNavigationController 继承 UINavigationController,在CusNavigationController.m中重写方法:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    UIViewController *vc = self.topViewController;
    if([vc isKindOfClass:[RegionViewController class]]){//要横屏的界面
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);//选择需要支持的翻转方向
    }
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);//其他界面均为竖屏

    }

    - (BOOL)shouldAutorotate {
    UIViewController *vc = self.topViewController;
    if([vc isKindOfClass:[RegionViewController class]]){//要横屏的界面
    return YES;
    }
    //横屏的上一个界面,要返回为YES,否则横屏返回的时候上一界面不能还原成竖屏
    if([vc isKindOfClass:[RootViewController class]]){
    return YES;
    }
    return NO;
    }
    3.在需要横竖屏翻转的ViewController.m(这里为RegionViewController) 重写以下方法:
    - (BOOL)shouldAutorotate {
    //是否允许转屏
    return YES;
    }

    - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    //viewController所支持的全部旋转方向
    return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight ;
    }

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    //viewController初始显示的方向
    return UIInterfaceOrientationPortrait;
    }
    4.如果使用了autolayout布局的话,可以实现横竖屏适配。

  • 相关阅读:
    多线程下System.Security.Cryptography.Aes CreateDecryptor报“Safe handle has been closed”的解决方案
    使用ConfuserEx加密混淆程序以及如何脱壳反编译
    使用Dotfuscator加密混淆程序以及如何脱壳反编译
    利用Javascript解决HTML大数据列表引起的网页加载慢/卡死问题。
    cefsharp 在高DPI下闪烁的问题
    spark 笔记 8: Stage
    spark 笔记 9: Task/TaskContext
    spark 笔记 7: DAGScheduler
    spark 笔记 5: SparkContext,SparkConf
    spark 笔记 6: RDD
  • 原文地址:https://www.cnblogs.com/gwca/p/7702141.html
Copyright © 2011-2022 走看看