iPhone自动旋转控制代码-IOS开发

声明
欢迎转载,但是请尊重作者劳动成果,转载请保留此框内声明,谢谢。
文章出处:http://blog.csdn.net/iukey




旋转有时候是很好的特性,但是并不是所有的程序界面都想旋转的,因为旋转会使得界面变得不和谐,除非你已经开发了专门针对各种方向的界面,所以有时候还是禁用旋转比较好,或者程序中的某个界面是横屏的,退出这个横屏视图之后界面又变成竖屏的,比如看视频或者浏览网页的时候你希望是横屏的,但是其他的工作你希望是竖屏的。OK,这一切都不是问题。我们可以通过代码来控制我们程序中每个界面的旋转功能。

在你想要设置的视图控制器里找到 shouldAutorotateToInterfaceOrientation: 方法,重写它的实现代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
系统通过调用此方法询问试图控制是否旋转到指定方向。系统共定义了4种方向,分别对应4种常见握持方式:
typedef enum {
    UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
    UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
    UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;
如果想要对任何情况都支持旋转只要返回YES即可,如果只想部分支持就对支持的返回YES 不支持的返回NO。


最后附上Demo代码:AutoOreintationDemo


原文链接: http://blog.csdn.net/iukey/article/details/7331757

转载于:https://my.oschina.net/junwong/blog/51623

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值