zoukankan      html  css  js  c++  java
  • 【Xamarin挖墙脚系列:IOS-关于手机支持的屏幕方向】

    设置支持的屏幕方向有两个级别,一个是app级别的,另一个是viewController级别的。

     

    app 级别的可以在[target]-[general]-[device orientation]里面设置,

    默认情况下Upside Down没有勾选,其他都勾选了。

    (为什么Upside Down不推荐勾选呢,因为iPhone的电话app是不支持Upside Down的,如果你的app支持Upside Down,万一用户在用你的app的时候Upside Down了,这时候来了电话,就会看到整个来电的画面是颠倒的,用户体验很不好。一向注重用户体验的苹果是不推荐你勾选Upside Down的)

    viewController级别的就是在各个viewController里面设置了。

    这里有一点需要注意,viewController的设置受app级别设置的限制,也就是viewController能够设置的屏幕方向只能是在app级别中勾选的一种或多种,没有勾选的是不能设置的。比如上面的Upside Down没有勾选,那么viewController也就不能设置Upside Down的方向。

    那么在viewController里面怎么设置屏幕方向呢?

    iOS6以前:

    // 设置屏幕只支持竖向
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    从iOS6开始,上面的方法已经被抛弃,有了3个新的方法:
     

    // 不支持屏幕旋转
    - (BOOL)shouldAutorotate
    {
    return NO;
    }

    // 只支持竖向
    - (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationPortrait;
    }

    // 画面一开始加载时就是竖向
    // - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    // return UIInterfaceOrientationPortrait;
    // }

    如果iOS6之前的版本也对应,那么被抛弃的那个方法也需要加上去。
     

    但是,iOS8.3开始,在有UIAlertView的viewController里面,弹出UIAlertView的时候会崩溃,Log信息如下:

    Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',
    reason: 'Supported orientations has no common orientation with the application,
    and [_UIAlertShimPresentingViewController shouldAutorotate] is returning YES'

    通过查阅官方文档,发现supportedInterfaceOrientations方法的返回值是UIInterfaceOrientationMask类型的,所以应该用UIInterfaceOrientationMaskPortrait。UIInterfaceOrientationMask类型从iOS6就有了,只不过到iOS8.3才会崩溃。
     

    至于preferredInterfaceOrientationForPresentation方法,返回值还是老的UIInterfaceOrientation类型。

  • 相关阅读:
    C博客作业00—我的第一篇博客
    C语言博客作业03函数
    C语言博客作业05指针
    快速分页:jsp标签pagertaglib
    JSP与Servlet的编解码
    初探Hibernate3源码读取配置文件
    截取图片的某个部分(C#源代码)
    使用MATLAB获取视频中每一帧的图像
    Windows下较为精确的计时方法
    [转]向Windows Phone 7手机部署应用程序
  • 原文地址:https://www.cnblogs.com/micro-chen/p/5245897.html
Copyright © 2011-2022 走看看