在 iOS 8/9 中基于设备方向的两个 View Controller 之间的首选方式是什么?我想构建一个以横向显示的仪器。在纵向中,我想显示应用程序的设置。
最佳答案
在 AppDelegate.swift 的“didFinishLaunchingWithOptions”函数中,我输入了:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
然后在 AppDelegate 类中,放置以下函数:
func rotated(){
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation){
println("landscape")
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)){
println("Portrait")
}
}
或者你可以使用这个:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
println("landscape")
} else {
println("portraight")
}
}
关于ios - 在 iOS 8/9 中根据设备方向更改 Viewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460049/