ios - 在 UISplitViewController 的详细 View 中呈现模态视图

标签 ios xcode ipad uinavigationcontroller uisplitviewcontroller

我想在横向模式的 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/

相关文章:

ios - 使用未解析的标识符 FBSDKAppEventNamePurchased

ios - 如何在 React Native 中禁用旋转?

iphone - 在 Storyboard 的 ScrollView 中显示项目

ios - MKMapView 似乎是零?

ipad - UIPopoverController 显示位置错误

objective-c - MPMoviePlayerController 控件在 UIModalPresentationFormSheet 样式模式中打开并且用户使视频全屏时

ios - 关闭 UITableView 单元格中 UITextfield 的键盘

iphone - 如何检查 UITableViewCells 是否为空白

xcode - 图像并非全部显示在模拟器上,而是显示在 Storyboard中

ios - UITableViewCell 详细信息披露按钮按钮在搜索过程中太靠右了