iOS presentedViewController 单屏幕旋转整理
2016-12-02 11:30
453 查看
关联:
① 简书专题
② iOS presentedViewController 单屏幕旋转整理
参考资料: iOS屏幕旋转二三事(Orientations)
效果图:
![](http://upload-images.jianshu.io/upload_images/133827-a5aec3bb02e51bd9.gif?imageMogr2/auto-orient/strip)
使用过多种单屏幕旋转的方式均宣告失败,要么是代码过于复杂臃肿,要么是实现方式欠佳,甚至根本无法实现或者直接崩溃。
经过多次多次尝试,暂时使用 模态窗口 实现单屏幕自动旋转,Push 的那种方式实现单屏幕旋转还有待考证,至今没找到逻辑思路清晰的资料(更有甚者居然要修改全部 Controller 文件,我有一句妈卖批不知当讲不当讲)。
在项目只有一种显示方向的时候,我们要实现单屏幕旋转简单粗暴的方式就是旋转 view 了,修改 frame 让用户感官上觉的是横屏的界面。
但是会有这样的问题:
大概是这样婶儿的
![](http://upload-images.jianshu.io/upload_images/133827-591f16690e98fce1.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](http://upload-images.jianshu.io/upload_images/133827-0600ebf96b4d60b3.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](http://upload-images.jianshu.io/upload_images/133827-dfab27e78baecf51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
说正事儿:
①首先配置工程如下(这步等价于在 info.plist 写入支持方向,必写!不然崩溃)
![](http://upload-images.jianshu.io/upload_images/133827-f13a3b81dfce8580.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
②AppDelegate.m 添加代码如下
③YourViewController.h 添加代码如下
YourViewController.m 添加代码如下
挺简单的,不给提供 Demo 了。另外有谁家大神有 Push 方式的单屏幕旋转方式,不妨在评论里给上链接。思路清晰,改动文件少的。我也会不遗余力的去尝试,找到一种正常点适合 push旋转的方法。
① 简书专题
② iOS presentedViewController 单屏幕旋转整理
参考资料: iOS屏幕旋转二三事(Orientations)
效果图:
![](http://upload-images.jianshu.io/upload_images/133827-a5aec3bb02e51bd9.gif?imageMogr2/auto-orient/strip)
使用过多种单屏幕旋转的方式均宣告失败,要么是代码过于复杂臃肿,要么是实现方式欠佳,甚至根本无法实现或者直接崩溃。
经过多次多次尝试,暂时使用 模态窗口 实现单屏幕自动旋转,Push 的那种方式实现单屏幕旋转还有待考证,至今没找到逻辑思路清晰的资料(更有甚者居然要修改全部 Controller 文件,我有一句妈卖批不知当讲不当讲)。
在项目只有一种显示方向的时候,我们要实现单屏幕旋转简单粗暴的方式就是旋转 view 了,修改 frame 让用户感官上觉的是横屏的界面。
但是会有这样的问题:
大概是这样婶儿的
![](http://upload-images.jianshu.io/upload_images/133827-dfab27e78baecf51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
说正事儿:
①首先配置工程如下(这步等价于在 info.plist 写入支持方向,必写!不然崩溃)
![](http://upload-images.jianshu.io/upload_images/133827-f13a3b81dfce8580.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
②AppDelegate.m 添加代码如下
#import "YourViewController.h"
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { //获取当前展示的最顶层 rootViewController UIViewController *rootController = self.window.rootViewController; if ([rootController.presentedViewController isKindOfClass:[YourViewController class]]) { YourViewController *yourViewVC = (YourViewController *)rootController.presentedViewController; if (yourViewVC.isPresented) { return UIInterfaceOrientationMaskPortrait;//竖屏 }else{ return UIInterfaceOrientationMaskLandscape;//左横 右横 } } else { return UIInterfaceOrientationMaskPortrait;//竖屏 } }
③YourViewController.h 添加代码如下
//记录当前控制器是否做了退出操作 @property (nonatomic, assign) BOOL isPresented;
YourViewController.m 添加代码如下
- (BOOL)shouldAutorotate { //进入当前页面应该返回 YES ,当退出后这里应该置 NO return !_isPresented; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { //本页面 支持方向 return UIInterfaceOrientationMaskLandscape;//左横和右横 } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { //进入页面 默认支持方向 return UIInterfaceOrientationLandscapeRight;//右横 } - (void)dismiss { self.isPresented = YES; [self dismissViewControllerAnimated:YES completion:nil]; }
挺简单的,不给提供 Demo 了。另外有谁家大神有 Push 方式的单屏幕旋转方式,不妨在评论里给上链接。思路清晰,改动文件少的。我也会不遗余力的去尝试,找到一种正常点适合 push旋转的方法。
![](http://upload-images.jianshu.io/upload_images/133827-869280ccd696d109.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
相关文章推荐
- ios6.0之后单个屏幕旋转,不用根视图以及Application windows are expected to have a root view controller at the end of
- iOS 的Viewcontroller只支持一个屏幕方向,弹出不同方向,旋转
- IOS TabBarController中是否允许单个viewController旋转屏幕
- ios6.0 UINavigationController、UITabBarController 支持屏幕自动旋转问题
- [iOS]技巧集锦:UICollectionView在旋转屏幕后Cell中的约束不起作用或自动布局失效
- iOS presentedViewController的基本使用
- IOS某个ViewController禁止自动旋转
- 当rootViewController为tabbarController时,控制屏幕旋转的方法
- iOS presentViewController 推出半屏幕透明 UIViewController
- ios navigationcontroller 滑动返回与webview加载html图片自适应屏幕宽度
- iosUIpageViewController转屏后里面的子视图没有跟着一起旋转
- iOS 疑难杂症(什么鬼系列)— — UITableView 添加 tableFooterView 旋转屏幕后收不到点击事件!!!
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
- iOS 开发,屏幕旋转、旋转屏幕collectionView cell 的自动布局问题
- iOS开发 获取当前正在显示的ViewController(包含Push的和presented的)
- IOS 使用UIPageViewController创建开始屏幕 附代码
- iOS 设置某个ViewController可以旋转
- iOS个人整理05-应用程序的启动流程--视图控制器ViewController的加载过程--MVC架构
- iOS系统自带的 **UIAlertView** 以及 屏幕自动旋转的实现
- IOS某个ViewController禁止自动旋转