美文网首页问题适配
iphone横竖屏的适配

iphone横竖屏的适配

作者: 三岁就很乖 | 来源:发表于2016-02-17 10:51 被阅读155次

    我的项目中个别的界面需要旋转屏幕,有的是不需要旋转的

    解决如下:就是把系统类子类化,再使用子类

    1.设置app级别的支持屏幕的方向

    targets -> General -> Deployment Info

    2.所有界面都有一个统一的BaseViewController,在这里实现ViewController级别的设置屏幕方向

    3.在tabbarController中设置屏幕方向

    4.在NavigationController中设置屏幕方向

    5.在要旋转的页面设置屏幕旋转如下:

    要旋转的view是通过这样展示

    [self presentViewController:perview animated:NO completion:nil];

    我这里应该是最笨的方法,屏幕旋转重新添加subviews,有待优化

    在开发中遇到的需要注意的问题

    1、UIAlertViewcontroller

    iOS 8 UIActionSheet ignores view controller supportedInterfaceOrientations and shouldAutorotate

    我做了一个·类扩展

    ```

    -(void)viewWillAppear:(BOOL)animated

    {

    if([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)]) {

    [[UIDevicecurrentDevice]performSelector:@selector(setOrientation:)withObject:UIPrintInfoOrientationPortrait];

    }

    }

    ```

    还看了一些stackoverflow中的问答

    http://stackoverflow.com/questions/25819132/ios-8-uiactionsheet-ignores-view-controller-supportedinterfaceorientations-and-s

    -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

    {

    UIViewController *presentedViewController = window.rootViewController.presentedViewController;

    if (presentedViewController) {

    if ([presentedViewController isKindOfClass:[UIActivityViewController class]] || [presentedViewController isKindOfClass:[UIAlertController class]]) {

    return UIInterfaceOrientationMaskPortrait;

    }

    }

    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;(这是view controller级别的屏幕方向)

    }

    2、

    deprecated表示已不被建议使用,可能随时取消它;建议采用新的来替代

    3、相关链接:

    http://blog.csdn.net/totogogo/article/details/8002173

    #if 0

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

    {

    // Return YES for supported orientations.

    return YES;

    }

    #endif

    #if 1

    - (BOOL)shouldAutorotate

    {

    return YES;

    }

    - (NSUInteger)supportedInterfaceOrientations

    {

    return UIInterfaceOrientationMaskAllButUpsideDown;

    }

    #endif

    http://mobile.51cto.com/iphone-407786.htm

    http://www.jianshu.com/p/73be6d0e152f

    http://blog.csdn.net/yuanxiubin/article/details/8752990

    BaseTabBarController  BaseNavigationController

    我都是先把系统类子类化 然后使用子类

    我所有的页面都有一个统一的 BaseViewController 、

    这里面实现了 #pragma mark 旋转

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

    {

    return UIInterfaceOrientationPortrait;

    }

    -(UIInterfaceOrientationMask)supportedInterfaceOrientations

    {

    return UIInterfaceOrientationMaskPortrait;

    }

    -(BOOL)shouldAutorotate

    {

    return NO;

    }

    然后在要旋转的页面 加入下面代码

    - (BOOL)shouldAutorotate

    {

    return NO;

    }

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

    {

    return UIInterfaceOrientationLandscapeRight;

    }

    -(UIInterfaceOrientationMask)supportedInterfaceOrientations

    {

    return UIInterfaceOrientationMaskLandscapeRight;

    }

    相关文章

      网友评论

        本文标题:iphone横竖屏的适配

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