IOS 中禁止横屏
来源:互联网 发布:百度竞价推广优化 编辑:程序博客网 时间:2024/05/22 00:21
#define UIInterfaceOrientationIsPortrait(orientation) ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown)
#define UIInterfaceOrientationIsLandscape(orientation) ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight)
-(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait;}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);}
其实只需要
//如果是ios6.0以上的:- (BOOL)shouldAutorotate{return NO;}6.0以下的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return NO;}//NO就是不支持翻转,记住要加在根视图上。具体什么时候返回yes就你自己判断了
对于pad横屏,可以这样使用
-(BOOL)shouldAutorotate{ return YES;}-(NSUInteger)supportedInterfaceOrientations{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; } return UIInterfaceOrientationMaskPortrait;}-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); } return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);}
对于支持同时支持phone和pad,在禁止phone横屏时,还要考虑pad可以横屏,所以要区分。
-(BOOL)shouldAutorotate{ return YES;}//phone只支持正方向,pad只支持左右横屏-(NSUInteger)supportedInterfaceOrientations{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; } return UIInterfaceOrientationMaskPortrait;}-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); } return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);}
四个朝向:
Portrait: 正方向,下面有home键
Upside Down: 反方向
Landscape Left: 向左横屏,Home键左方
Landscape Right:向右横屏
0 0
- IOS中禁止横屏
- IOS 中禁止横屏
- ios 6中如何禁止横屏
- IOS中如何禁止横屏
- ios 禁止横屏
- iOS 禁止横屏
- ios 禁止横屏
- ios 禁止横屏
- ios 禁止横屏
- ios 禁止横屏
- iOS 禁止横屏
- iOS 禁止横屏
- iOS 禁止横屏
- iOS 禁止横屏
- iOS 禁止横屏
- ios 禁止横屏
- iOS---禁止横屏
- iOS 禁止横屏
- Thermal计算方式小结
- 一段代码教你看懂Hibernate一级缓存与懒加载
- 页面跳转
- 乐观锁更新失败重试解决方案
- 刚体
- IOS 中禁止横屏
- MAC Tree 实现的方法(NSOutlineView) 2 (实现了简单的选择和动态修改不同的数据)
- APCI ASL
- 【北风网】十一大放“价”,折上折,全场IT课程3折起
- Javascript中parseInt在XSS中的应用
- JAVA正则表达式 Pattern和Matcher
- HttpClient Request Demo
- Spring MVC 实现文件上传与下载
- IE 6不支持PNG图片透明 -- 解决办法