Getting device orientation in Swift

后端 未结 13 1441
滥情空心
滥情空心 2020-11-28 23:23

I was wondering how I can get the current device orientation in Swift? I know there are examples for Objective-C, however I haven\'t been able to get it working in Swift.

13条回答
  •  Happy的楠姐
    2020-11-28 23:29

    I found that the alternative code in Swift for the Obj-C code

    if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) 
    

    is

    if UIApplication.shared.statusBarOrientation.isLandscape
    

    Note: we are trying to find the status bar orientation is landscape or not. If it is landscape then the if statement is true.

提交回复
热议问题