iOS8 - 防止在呈现 viewController 时旋转 [英] iOS8 - prevent rotation on presenting viewController

查看:16
本文介绍了iOS8 - 防止在呈现 viewController 时旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有 tableView 的 MainViewController,它提供了一个新的 modalViewController.

We have a MainViewController with a tableView, and it presents a new modalViewController.

MainViewController 仅限纵向,modalViewController 可以旋转.

The MainViewController is restricted to portrait only, and the modalViewController can rotate.

问题出在iOS8中,modalViewController旋转时,在MainViewcontroller中调用了iOS8中旋转的回调方法--(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator

The problem is in iOS8, that when the modalViewController rotates, the callback method of rotation in iOS8 in MainViewcontroller is called - - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

因此,UITableView 正在重新加载其数据,这是我们不希望的行为.

Thus, the UITableView is getting its data reloaded, which is a behaviour we don't want.

我们可以阻止 iOS 8 的这个功能,而不是旋转呈现的 UIViewController 吗?

Can we prevent this feature of iOS 8, and not rotate the presenting UIViewController?

推荐答案

所以经过几天的搜索和调查,我终于想出了一个可能的解决方案.

So after long days of searching and investigating, I finally came up with a possible solution.

首先,我可以使用导航控制器并推送 viewController 而不是呈现它,但它破坏了我的代码并且不是那么正确.

First of all, I can use navigation controller and push the viewController instead of presenting it, but it breaks my code and just isn't so true.

我能做的第二件事是不设置约束.我仍然可以使用自动布局,但如果我不设置约束,并设置默认约束,tableView 不会重新加载.当然这也不是很聪明的事情,因为我的 viewController 中有很多元素.

The second thing I can do is not setting constraints. I still can use autolayout, but if I don't set constraints, and let the default constraints to be set, the tableView doesn't get reloaded. of course this is also isn't very smart thing to do, as I have many elements in my viewController.

最后,我发现我可以在另一个 UIWindow 中显示这个模态"视图控制器.我创建 UIWindow 并将 modalViewController 设置为其 rootViewController.

Finally, I figured out that I can show this "modal" viewController in another UIWindow. I create UIWindow and set the modalViewController as its rootViewController.

我在 git 中放了一些示例项目:https://github.com/OrenRosen/ModalInWindow

I put some example project in git: https://github.com/OrenRosen/ModalInWindow

希望对您有所帮助.

这篇关于iOS8 - 防止在呈现 viewController 时旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆