我想在横向模式的 iPad 中做一个类似通讯录应用的行为。
我希望当我点击上方的右添加按钮 时,模态框会显示在详细信息 View 中。
但现在如果我点击右上角的添加按钮,模态显示在所有屏幕中。
我应该使用什么方法?显示细节 View Controller ?或 presentViewController?我不知道如何仅在详细 View 中显示模态。
最佳答案
首先你需要设置细节 View Controller 的属性definesPresentationContext = true
。所以现在它定义了 presentation context 。默认情况下, View Controller 在呈现时不会关注当前上下文,因此您必须执行 viewController.modalPresentationStyle = .CurrentContext
这就是完整方法的样子
func adaptivePresentViewController(viewController: UIViewController) {
let detailVC = splitViewController!.viewControllers[1]
detailVC.definesPresentationContext = true
viewController.modalPresentationStyle = .CurrentContext
detailVC.presentViewController(viewController, animated: true, completion: nil)
}
关于ios - 在 UISplitViewController 的详细 View 中呈现模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992170/