扫码关注官方订阅号
需求是这样的:整个App的大部分界面都是竖屏显示,且只允许竖屏显示。只有单独几个页面可以切换横竖屏,比如视频播放页面,图片浏览界面。
按照网上的方法试了好久,都没成功,求助!!!
人生最曼妙的风景,竟是内心的淡定与从容!
在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 *)[UIApplication sharedApplication].delegate; _appDelegate.allowRotation = 1;
在要这个controller要消失的时候 写_appDelegate.allowRotation = 0;就可以了
关于设备的旋转方法,前面两个返回NO,就不支持旋转了,最后一个支持的旋转方向
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return NO;}
(BOOL)shouldAutorotate{ return NO;}
(UIInterfaceOrientationMask)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll;}
你是如何解决的
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
在AppDelegate.m中
写这两个方法
在你要旋转的controller中一开始的地方写这两句就可以了
在要这个controller要消失的时候 写_appDelegate.allowRotation = 0;就可以了
关于设备的旋转方法,前面两个返回NO,就不支持旋转了,最后一个支持的旋转方向
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
(BOOL)shouldAutorotate
{
return NO;
}
(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
你是如何解决的