搜索
ios中横屏和竖屏如何共存??
迷茫
迷茫 2017-04-17 11:21:36
[iOS讨论组]

ios中可以设置是横屏还是竖屏。但如果你在xcode中同时选择了横屏和竖屏,当你旋转屏幕时,你的view就会同时就会跟着旋转。我现在的问题时,我的app要有两个view,一个是支持横屏的,但它不能选择,永远横屏。另外一个是竖屏的,永远是竖屏的,也不能再选择。两个view通过一个button关联,点一下,进入另一个。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
怪我咯

没地方放压缩包,我就在这里写个简单吧,2个UIViewController,你自己新建一个工程就加两按钮就可以测试。
核心需要添加的方法如下:

1,PortraitViewController 不旋转,保持竖屏

//iOS 5
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
//iOS 6
- (BOOL)shouldAutorotate
{
	return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
	return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
	return UIInterfaceOrientationPortrait;
}

LandscapeViewController 始终保持横屏

//iOS 5
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation);
}
//iOS 6
- (BOOL) shouldAutorotate
{
	return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
	return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
	return UIInterfaceOrientationLandscapeRight;
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号