前言:
此刻大家对“前端判断ios或者安卓”大致比较关注,小伙伴们都想要知道一些“前端判断ios或者安卓”的相关知识。那么小编也在网摘上收集了一些关于“前端判断ios或者安卓””的相关知识,希望朋友们能喜欢,各位老铁们一起来了解一下吧!监听设备方向
deinit { // 移除通知 NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil) // 结束 UIDevice.current.endGeneratingDeviceOrientationNotifications()} override func viewDidLoad() { super.viewDidLoad() // 注册 UIDevice.current.beginGeneratingDeviceOrientationNotifications() // 监听 UIDevice.orientationDidChangeNotification NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)} @objc fileprivate func orientationDidChange() { switch UIDevice.current.orientation { case .unknown: print("unknown") case .portrait: print("竖屏") setupGridView() case .portraitUpsideDown: print("颠倒竖屏") case .landscapeLeft: print("向左旋转横屏") setupGridView() case .landscapeRight: print("向右旋转横屏") setupGridView() case .faceUp: print("朝上") case .faceDown: print("朝下") default: break }}判断设备方向
if UIDevice.current.orientation.isPortrait { print("竖屏")}if UIDevice.current.orientation.isLandscape { print("横屏")}if UIDevice.current.orientation.isFlat { print("水平")}if UIDevice.current.orientation.isValidInterfaceOrientation { print("有效")}
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #前端判断ios或者安卓