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

ios 6 横竖屏转换

程序的根控制器用了UINavigationController。下面是代码:

1.在appdelegate中添加代码:


- (NSUInteger)application:(UIApplication *)application supportedInte易做图ceOrientationsForWindow:(UIWindow *)window

{

    return UIInte易做图ceOrientationMaskAll;

}

2.给UINavigationController添加个category,在实现文件中添加如下代码:

-(BOOL)shouldAutorotate

{

    return [[self topViewController] shouldAutorotate];

}

 


-(NSUInteger)supportedInte易做图ceOrientations

{

    return [[self topViewController] supportedInte易做图ceOrientations];

}

 


- (UIInte易做图ceOrientation)preferredInte易做图ceOrientationForPresentation

{

    return [[self topViewController] preferredInte易做图ceOrientationForPresentation];

}

3.在需要横屏的地方添加(竖屏可以更换方向):

-(NSUInteger)supportedInte易做图ceOrientations{

   

    return UIInte易做图ceOrientationMaskLandscapeRight;  // 可以修改为任何方向

}

-(BOOL)shouldAutorotate{

    return YES;

}

 


- (BOOL)shouldAutorotateToInte易做图ceOrientation:(UIInte易做图ceOrientation)inte易做图ceOrientation {

    return inte易做图ceOrientation == UIInte易做图ceOrientationLandscapeRight;

}

4.最重要的是:页面之间切换不能用导航控制器切换,必须使用:

[self presentViewController:navigationController animated:YES completion:Nil];

 

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,