1.UIViewController的转屏回调
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration API_DEPRECATED("Implement viewWillTransitionToSize:withTransitionCoordinator: instead", ios(2.0, 8.0)) API_UNAVAILABLE(tvos);
从这个接口的声明中可以看出来,在iOS8之后废弃这个方法了,而现在很多APP都支持到iOS9及以上了,这个时候,需要用后面提供的方法:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
2.参考链接:
https://www.jianshu.com/p/6c2368650ad7
方法1:监听:UIDeviceOrientationDidChangeNotification 通知
文章中介绍说,这个通知会有一定问题,1.UIDeviceOrientation改变时,UIInterfaceOrientation不一定改变。
方法2:监听 UIApplicationWillChangeStatusBarOrientationNotification 通知
Posted when the app is about to change the orientation of its interface. ----当用户界面方向将要改变时,发出该通知。
UIApplicationDidChangeStatusBarOrientationNotification --- 当用户界面方向已经改变了,发出该通知。
项目中,目前使用的是VC自身的转屏回调,相对准确和靠谱一些。