IOS屏幕旋转
2018-07-20 来源:open-open
//在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation:
//来单独控制某个UIViewController的旋屏方向支持
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
//但是在iOS6中,这个方法被废弃了,取而代之的是这俩个组合:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
//设置View Controller被Presented时的首选显示方向。
//当view controller被presented显示时,可能在一个特定的方向显示最合适,如果其仅仅支持这一个方向
//可以在supportedInterfaceOrientations方法中简单的返回此方向,但如果view controller支持多个方向显示
//但在某一个方向显示最佳,则可以通过重写preferredInterfaceOrientationForPresentation方法来返回此方向
//这样,当view controller被presented时,将会以preferredInterfaceOrientationForPresentation返回的方向显示。
//注意:preferredInterfaceOrientationForPresentation返回的方向是supportedInterfaceOrientations中的一个。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
//如果整个应用所有view controller都不支持旋屏
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
//获取到“当前interfaceOrientation
//具体区别,可参见StackOverflow的问答:
//http://stackoverflow.com/questions/7968451/different-ways-of-getting-current-interface-orientation
controller.interfaceOrientation,获取特定controller的方向
[[UIApplication sharedApplication] statusBarOrientation] 获取状态条相关的方向
[[UIDevice currentDevice] orientation] 获取当前设备的方向
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐