美文网首页iOS-开发菜鸟->大神开发
iOS 横竖屏的正确打开姿势

iOS 横竖屏的正确打开姿势

作者: e5311f1a36e5 | 来源:发表于2017-06-12 19:10 被阅读24次

一、使用场景概述

  • 一种是在present出来的vc中打开横竖屏

  • 固定只有一个方向(横屏的方向)

  • 可根据重力感应进行横竖屏

  • 某个特定的push出来的vc中打开横竖屏(只能根据重力感应横竖屏,不能设置强制的方向)

二、具体代码解释

  • 要打开横竖屏功能需要打开开关同时设置ViewController的三个方法(必须要设置)

  • 然后需要注意固定一个方向显示时和根据重力感应时的shouldAutorotate的返回值是不一样的

  • 需要注意在离开vc时一定要关闭横竖屏,否则会导致整个APP显示错乱


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    ALLOWROTATION
}

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

- (BOOL)shouldAutorotate{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

三、重点在这

相关文章

网友评论

    本文标题:iOS 横竖屏的正确打开姿势

    本文链接:https://www.haomeiwen.com/subject/uhblqxtx.html