1 屏幕旋转和全屏:
首先必须在根控制器中设置shouldAutorotate,
如果根控制器设置为self.window?.rootViewController = BaseNavigationController(rootViewController: ViewController())
则必须在BaseNavigationController内设置,想要在不同控制器中自定义是否选装,女啊中代码如下
override func shouldAutorotate() -> Bool {
return (self.topViewController?.shouldAutorotate()) ?? false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations()) ?? [.Portrait]
}
在特定控制器中代码:其中view为你需要放大缩小全屏展示的view
override func shouldAutorotate() -> Bool {
return true
}
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
super.willRotateToInterfaceOrientation(toInterfaceOrientation, duration: duration)
switch toInterfaceOrientation {
case .Unknown:
print("未知方向")
break
case .LandscapeLeft:
print("屏幕向左横置")
view.frame = CGRectMake(0, 0, P.height , P.width)
self.verticalView.hidden = true
break
case .LandscapeRight:
print("屏幕向右横置")
view.frame = CGRectMake(0, 0, P.height , P.width)
break
case .Portrait:
view.frame = CGRectMake(0, 44, P.width , P.width * scale)
print("屏幕直立")
break
case .PortraitUpsideDown:
print("屏幕直立,上下颠倒")
break
default:
print("无法辨别")
break
}
}