iOS Swift5.0项目强制竖屏或者强制横屏
2021-12-13 本文已影响0人
Lee坚武
在info.plist中
- 找到“Supported interface orientations”,
- 去掉“Portait(bottom home button)”和“Landscape(left home button)”,
- 留下“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相关技术!