在 UISplitViewController 中以编程方式显示/隐藏主视图 [英] Programmatically show / hide master view in UISplitViewController

查看:24
本文介绍了在 UISplitViewController 中以编程方式显示/隐藏主视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 UISplitViewController 的应用程序.在横向时,我们有时希望一直显示主视图,有时希望它像纵向那样自动隐藏.目前可以在应用中调整此设置.

I have an app that uses a UISplitViewController. When in Landscape orientation, we sometimes want to show the master view all the time and sometimes want it to auto hide as it does in portrait orientation. Currently this setting can be tweaked in app.

这一切都很好,除了一件事.当我更改设置时,我希望自动隐藏设置立即生效,而不仅仅是在我下次旋转设备时(即当 - splitViewController:shouldHideViewController:inOrientation: 被调用时).

This all works well, except for one thing. When I change the setting, I'd like the auto-hide setting to take effect immediately, not just the next time I rotate the device (i.e. when - splitViewController:shouldHideViewController:inOrientation: is called).

有没有办法(以编程方式)强制 UISplitViewController 弹出/隐藏主视图,以便 SVC 再次查询 splitViewController:shouldHideViewController:inOrientation: 方法?

Is there some way to (programmatically) force the UISplitViewController to pop out / hide the master view so that the SVC will query the splitViewController:shouldHideViewController:inOrientation: method again?

任何帮助将不胜感激.

推荐答案

没有直接的方法.

一个功能强大但有点麻烦的解决方案是设置一个委托并记录在显示/隐藏母版时传递给委托的 barButtonItem.您可以使用它来触发按钮上的操作.但是,正如我所说,这并不是一个很好的方法(并且将来可能会中断):

A functional, yet a little hacky solution would be to set a delegate and record the barButtonItem passed to the delegate when showing/hiding the master. You can use it to just trigger the action on the button. But, as I said, this is not really a nice way of doing it (and may break in the future):

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
    _buttonItem = barButtonItem;
    // ...
}

- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)button
{
    _buttonItem = nil;
    // ...
}

- (void)toggleMasterVisible
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [_buttonItem.target performSelector:_buttonItem.action];
#pragma clang diagnostic pop
}

这篇关于在 UISplitViewController 中以编程方式显示/隐藏主视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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