IOS强制横竖屏幕切换总结续
2015-08-04 19:52
369 查看
在不了解强制旋转屏幕的概念先看看之前的文章:http://blog.csdn.net/zsykile/article/details/47169347
现在已经确定,把工程设置关闭照样在代码中可以截获横竖屏的控制权力!
这个文章主要是对 一些我之前遇到的 纠结的地方做一个 解答,在之前的项目中 工程横竖屏设置已经彻底关闭。从视频列表到 视频详情界面是push的过程,然后写上了旋转代码
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.makeOrientation = UIInterfaceOrientationLandscapeRight;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
界面死活不转只看见 UIAlertView 在转。折腾了一天,最后在下班的时候发现根视图没有用
UINavigationController 直接用了UIViewController的类别的UINavigationController,难怪转不过来,于是就把
UIViewController加入到UINavigationController里,心想这下可以转了,最后运行,还是没有转。又查找了好几个小时,发现工程里面有个UINavigationController的类别。里面写了这样的代码
- (BOOL) shouldAutorotate
{
return NO;
}
差点让这句代码害死,于是赶紧注释掉,再运行就可以旋转了!
所以 在UINavigationController写关于控制旋转的代码要小心,不同的场合用不同的代码
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;//UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;//UIInterfaceOrientationLandscapeRight;
}
- (BOOL) shouldAutorotate
{
return NO;
}
还有不同的界面是否要写上面的代码要仔细考虑!总结一下:强制旋转必须基于UINavigationController,最后附上demo
现在已经确定,把工程设置关闭照样在代码中可以截获横竖屏的控制权力!
这个文章主要是对 一些我之前遇到的 纠结的地方做一个 解答,在之前的项目中 工程横竖屏设置已经彻底关闭。从视频列表到 视频详情界面是push的过程,然后写上了旋转代码
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.makeOrientation = UIInterfaceOrientationLandscapeRight;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
界面死活不转只看见 UIAlertView 在转。折腾了一天,最后在下班的时候发现根视图没有用
UINavigationController 直接用了UIViewController的类别的UINavigationController,难怪转不过来,于是就把
UIViewController加入到UINavigationController里,心想这下可以转了,最后运行,还是没有转。又查找了好几个小时,发现工程里面有个UINavigationController的类别。里面写了这样的代码
- (BOOL) shouldAutorotate
{
return NO;
}
差点让这句代码害死,于是赶紧注释掉,再运行就可以旋转了!
所以 在UINavigationController写关于控制旋转的代码要小心,不同的场合用不同的代码
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;//UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;//UIInterfaceOrientationLandscapeRight;
}
- (BOOL) shouldAutorotate
{
return NO;
}
还有不同的界面是否要写上面的代码要仔细考虑!总结一下:强制旋转必须基于UINavigationController,最后附上demo
相关文章推荐
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取"产品付费数量等于0的问题"】
- ios圆角提高性能
- ios学习笔记--(oc基础3)
- iOS 获取当前时间
- iOS之触摸事件和手势
- iOS界面-仿网易新闻左侧抽屉式交互
- iOS Xcode6 新建OC Category文件
- 27个提升效率的iOS开源库推荐 第三方开放框架
- 【读书笔记】iOS-安全地传输用户密码的方法
- 【读书笔记】iOS-安全地传输用户密码的方法
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- ios修改textField的小技巧
- iOS中bundle的意义
- iOS开发里的Bundle是个啥玩意?!
- iOS开发之地图-----01定位CoreLocation
- IOS storyboard 和模拟器的尺寸大小不符,选择的是iPhone6 但 storyboard面板太大!!!
- webrtc开发中,音频实时对讲采集的问题(ios mic mute)
- iOS keyChain 研究
- iOS依赖注入框架系列(三):模块化Typhoon
- iOS依赖注入框架系列(二):设置Typhoon