我想知道iPhone当前处于纵向模式还是横向模式。如果我强制执行“纵向方向模式”,则可以通过编程方式知道。
我们可以知道iPhone的“人像方向锁定”是否处于打开/关闭状态
•
问答
zhengshinanhai 回答:我们可以知道iPhone的“人像方向锁定”是否处于打开/关闭状态
您只需使用orientation
即可获取当前设备的方向,
UIDevice.currentDevice().orientation
要检查人像模式,只需执行
if UIDevice.currentDevice().orientation == .portrait {
//add your code here...
}
这些可能是orientation
的值,
public enum UIDeviceOrientation : Int {
case unknown
case portrait // Device oriented vertically,home button on the bottom
case portraitUpsideDown // Device oriented vertically,home button on the top
case landscapeLeft // Device oriented horizontally,home button on the right
case landscapeRight // Device oriented horizontally,home button on the left
case faceUp // Device oriented flat,face up
case faceDown // Device oriented flat,face down
}