iOS在某界面强制横屏
迷茫
迷茫 2017-04-17 11:48:21
[iOS讨论组]

假设前一界面是竖屏,我进入新的viewcontroller,我想让当前界面在初始显示时强制横屏,那要怎么写?跪求指导,跪求千万别百度一下然后回答我,baidu的各种答案我试过,不好用。。。。

迷茫
迷茫

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

全部回复(4)
怪我咯

自己回答一下,在你需要横屏的viewcontroller中加入,project中的设置要支持landscaperight

- (BOOL) shouldAutorotateToInterfaceOrientation:
            (UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}
还有一个问题就是关于转屏是从底部向上的,也就是说,假设当你用navigationcontroller来跳转界面的时候,跳转到的界面的转屏控制与navigationcontroller里的转屏控制是相关的,具体的关联大家自己测试吧
天蓬老师

我的需求也是竖屏的tabbarcontroller,push到一个横屏的viewcontroller,返回后还是竖屏,只要在这个viewcontroller中加入以下代码就可以了,只在iOS5+测试过

  • (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); }

  • (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; }

黄舟

大哥 我用你这个方法没成功啊 打断点不会执行 我需要横屏的界面是push出来的第三层

阿神

http://www.cnblogs.com/niit-soft-518/p/5611298.html
请看博客,这里我整理了三种强制横屏的方法。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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