加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

IOS屏幕旋转

发布时间:2020-12-16 07:45:58 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 //在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation: //来单独控制某个UIViewController的旋屏方向支持- (BOOL)shou

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

//在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] 获取当前设备的方向

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读