在iOS8中使用UISplitViewController隐藏主视图控制器 [英] Hiding the master view controller with UISplitViewController in iOS8

查看:506
本文介绍了在iOS8中使用UISplitViewController隐藏主视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Xcode主从模板的iOS7应用程序,我正在移植到iOS8。一个已经发生了很大变化的领域是 UISplitViewController



在纵向模式下,如果用户点击了详细视图控制器,主视图控制器被解除:





如果用户点击一行,我还希望能够以编程方式隐藏主视图控制器。



在iOS 7中,主视图控制器显示为弹出窗口,可以隐藏如下:

  [self.masterPopoverController dismissPopoverAnimated:YES]; 

对于iOS 8,主服务器不再是popover,因此上述技术无效。 / p>

我试图解雇主视图控制器:

  self .dismissViewControllerAnimated(true,completion:nil)

或告诉拆分视图控制器显示详细信息视图控制器:

  self.splitViewController?.showDetailViewController(bookViewController!,sender:self)

但到目前为止还没有任何工作。任何想法?

解决方案

按如下方式扩展UISplitViewController:

 扩展名UISplitViewController {
func toggleMasterView(){
let barButtonItem = self.displayModeButtonItem()
UIApplication.sharedApplication()。sendAction(barButtonItem.action,to: barButtonItem.target,from:nil,forEvent:nil)
}
}

didSelectRowAtIndexPath prepareForSegue 中,执行以下操作:

  self.splitViewController?.toggleMasterView()

这将顺利将主视图滑开。



我想到了使用这篇文章我按照这篇文章模拟了它。



我对此并不满意解决方案,因为它似乎是一个黑客。但它运作良好,似乎没有其他选择。


I have an iOS7 application, which was based on the Xcode master-detail template, that I am porting to iOS8. One area that has changed a lot is the UISplitViewController.

When in portrait mode, if the user taps on the detail view controller, the master view controller is dismissed:

I would also like to be able to programmatically hide the master view controller if the user taps on a row.

In iOS 7, the master view controller was displayed as a pop-over, and could be hidden as follows:

[self.masterPopoverController dismissPopoverAnimated:YES];

With iOS 8, the master is no longer a popover, so the above technique will not work.

I've tried to dismiss the master view controller:

self.dismissViewControllerAnimated(true, completion: nil)

Or tell the split view controller to display the details view controller:

self.splitViewController?.showDetailViewController(bookViewController!, sender: self)

But nothing has worked so far. Any ideas?

解决方案

Extend the UISplitViewController as follows:

extension UISplitViewController {
    func toggleMasterView() {
        let barButtonItem = self.displayModeButtonItem()
        UIApplication.sharedApplication().sendAction(barButtonItem.action, to: barButtonItem.target, from: nil, forEvent: nil)
    }
}

In didSelectRowAtIndexPath or prepareForSegue, do the following:

self.splitViewController?.toggleMasterView()

This will smoothly slide the master view out of the way.

I got the idea of using the displayModeButtonItem() from this post and I am simulating a tap on it per this post.

I am not really happy with this solution, since it seems like a hack. But it works well and there seems to be no alternative yet.

这篇关于在iOS8中使用UISplitViewController隐藏主视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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