iOS使App中某一个界面强制横屏布局?
大家讲道理
大家讲道理 2017-04-17 17:22:39
[iOS讨论组]

App中其它界面都是竖屏, 只有一个界面是需要横屏的, 怎样使这个界面强制横屏布局?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(3)
ringa_lee

如果需要特定ViewController旋转, 可以为UINavigationController添加Category(类目)UINavigationController+InterfaceOrientation, 然后在指定的ViewController中调用即可.

@implementation UINavigationController (InterfaceOrientation)
- (BOOL)shouldAutorotate
{
    if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
        return [self.topViewController shouldAutorotate];
    }
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
        return [self.topViewController supportedInterfaceOrientations];
    }
    return [super supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
        return [self.topViewController preferredInterfaceOrientationForPresentation];
    }
    return [super preferredInterfaceOrientationForPresentation];
}
@end

另外, 推荐一篇博文: http://www.molotang.com/articles/1530.html. 对于不同级别的屏幕旋转梳理的较为清晰.

巴扎黑

使用如下这种方式,在需要横屏的页面添加。


- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
伊谢尔伦

那怎么保证其它界面始终是竖屏呢

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

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