iOS部分页面横竖屏解决方案
来源:互联网 发布:mac迅雷下到46没速度 编辑:程序博客网 时间:2024/06/06 04:49
系统支持横屏顺序
默认读取plist里面设置的方向(优先级最高)等同于Xcode Geneal设置里面勾选
application window设置的级别次之
然后是UINavigationcontroller/UITabbarController
级别最低的是viewcontroller
(注意Xcode Geneal设置里面没有勾选的方向viewcontroller强制旋转到该方向会crash)
旋转屏幕相关的几个重要方法:
//是否能旋转屏幕
- (BOOL)shouldAutorotate {
return YES;
}
//支持旋转的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
//强制旋转屏幕,私有方法 direction:UIInterfaceOrientation
NSNumber * value = [NSNumbernumberWithInteger:direction];
[[UIDevicecurrentDevice]setValue:valueforKey:@"orientation"];
几个旋转屏幕的小技巧:
1.项目中大多数页面都不支持旋转在rootViewController中shouldAutorotate方法中返回NO即可,对于支持旋转的我们使用presentViewController方法推出页面。
2.从支持旋转的页面A,push到不支持旋转的页面B 这里实现一个UINavigationController类重写一下方法:
//是否能旋转屏幕
- (BOOL)shouldAutorotate {
returnself.topViewController.shouldAutorotate;
}
//支持旋转的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
returnself.topViewController.supportedInterfaceOrientations;
}
在B页面shouldAutorotate方法中返回NO,推出B页面之前强制旋转为竖屏即可。
3.在设备已经旋转为横屏的状态下,从竖屏A,present到支持横屏的页面B,发现推出的直接是横屏,为了交互的一致性,希望推出的还是竖屏,可以在viewDidLoad,和viewDidAppear方法中先后设置self.needAutorotate为NO,和YES
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if (self.needAutorotate ==YES) {
returnUIInterfaceOrientationMaskAllButUpsideDown;
}
returnUIInterfaceOrientationMaskPortrait;
}
4.设备强制旋转后键盘弹出的方向不对,一定是supportedInterfaceOrientations返回的参数不对,调试下就ok了5.对于一会可以自由旋转一会不能旋转的需求也是对supportedInterfaceOrientations返回参数做文章。
- iOS部分页面横竖屏解决方案
- iOS 部分页面的强制横竖屏
- ios横竖屏解决方案
- ios横竖屏解决方案
- ios横竖屏解决方案
- iOS横竖屏解决方案
- iOS横竖屏解决方案
- iOS横竖屏解决方案
- 允许部分页面横竖屏
- iOS终极横竖屏切换解决方案
- iOS终极横竖屏切换解决方案
- [iOS]终极横竖屏切换解决方案
- iOS横竖屏切换解决方案(转载)
- [iOS]终极横竖屏切换解决方案
- ios 控制页面的横竖屏
- iOS手机APP页面横竖屏设置
- 【iOS】个别页面的横竖屏设置
- 移动端横竖屏显示页面不全解决方案
- vs2008编译zlib库32位及64位
- C#奇妙的函数(1)-五个序列聚合运算(Sum, Average, Min, Max,Aggregate)
- Code(一)排序算
- 【LeetCode】Longest Consecutive Sequence
- 存储过程的监控表DBA_proc_log
- iOS部分页面横竖屏解决方案
- Jquery给动态添加的元素绑定事件:live() delegate() on()
- 百倍增长,数据驱动——【云栖实录】面对正在崛起的移动支付,如何做好数据运营
- 网络请求缓存和判断网络
- apache配置文件,httpd.conf详解
- 可视化图表工具的选择
- ubuntu中apt-get安装与默认路径
- 小米5 Android7.0 ROOT教程
- 我的博客的开始与期望