iOS指定页面屏幕旋转

来源:互联网 发布:王珊数据库视频 编辑:程序博客网 时间:2024/06/08 03:51

在网上找了好久,大多数都是一样的使用起来没有效果,后来发现这个方法,确实好使。

首先在target中设置


在AppDelegate.m中

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{    if (_allowRotation == 1) {        return UIInterfaceOrientationMaskAll;    }else{        return (UIInterfaceOrientationMaskPortrait);    }}// 支持设备自动旋转- (BOOL)shouldAutorotate{    if (_allowRotation == 1) {        return YES;    }    return NO;}
在你要旋转的controller中一开始的地方写下面两句就可以了:

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; AppDelegate * appDelegate.allowRotation = 1;

在要这个controller要消失的时候 写appDelegate.allowRotation = 0;就可以了,不要写在viewWillDisappear中而是写在退出VC的触发事件中:

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; AppDelegate * appDelegate.allowRotation = 0;


原创粉丝点击