在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。
通过以上步骤就可以了。
更多方法交流可以家魏鑫:lixiaowu1129,一起探讨iOS相关技术!