美文网首页
iOS Swift5.0项目强制竖屏或者强制横屏

iOS Swift5.0项目强制竖屏或者强制横屏

作者: Lee坚武 | 来源:发表于2021-12-13 16:15 被阅读0次

    在info.plist中

    1. 找到“Supported interface orientations”,
    2. 去掉“Portait(bottom home button)”和“Landscape(left home button)”,
    3. 留下“Landscape(right home button)”。

    在ViewController类中的viewDidLoad()方法中添加

    UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
    

    重载添加这个方法

    //强制竖屏
    
        override var shouldAutorotate:Bool{
    
            return false
    
        }
    

    将返回值设为false。

    通过以上步骤就可以了。

    image.png

    更多方法交流可以家魏鑫:lixiaowu1129,一起探讨iOS相关技术!

    相关文章

      网友评论

          本文标题:iOS Swift5.0项目强制竖屏或者强制横屏

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