当前位置:编程学习 > wap >>

iOS 6 手持方向处理

iOS6手持方向处理
从iOS 5的应用程序更新到iOS6很多特性没法正常工作。主要的问题是,有一些API在新的SDK中已被弃用。其中手持方向的判断就是很明显的一个

存在的问题
假如你应用程序只有一个屏要是横向,其它的屏都要是纵向。

iOS 5的解决方案
在应用程序的Info.plist文件,Supported interface orientations应该只包含一个项目,Portrait 。

接下来,在需要的方向锁定为横向视图控制器类,你需要重写- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation方法,并返回YES或NO相对一个布尔值,检查对interfaceOrientation参数。

下面是函数看起来像什么。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
iOS的6解决方案
在iOS 6 -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 方法已过时,似乎没有被调用了。代替它的一组方法;-(BOOL)shouldAutorotate 和-(NSUInteger)supportedInterfaceOrientations的。

在UIViewController,你要在横向的,你需要同时重写- (BOOL)shouldAutorotate- (NSUInteger)supportedInterfaceOrientations的:

// iOS6中过时, 为了兼容iOS5.
// ---
- (BOOL)shouldAutorotateToInterfaceOrientation:
        (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

// iOS6 support
// ---
- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
// ---

补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,