您的位置:首页 > 移动开发 > IOS开发

[置顶] iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏

2017-09-07 15:49 746 查看
在AppDelegate 中实现以下两个方法

/**

iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏?

在你要旋转的controller中一开始的地方写这两句就可以了

- (void)setupView{

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

appDelegate.allowRotation = 1;

}

- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];

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

appDelegate.allowRotation = 0;

}

@param application <#application description#>
@param window <#window description#>
@return <#return value description#>
*/
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (_allowRotation == 1) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return (UIInterfaceOrientationMaskPortrait);
}
}

// 支持设备自动旋转
- (BOOL)shouldAutorotate
{
if (_allowRotation == 1) {
return YES;
}
return NO;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: