将UISplitViewController隐藏在肖像中 [英] Hiding UISplitViewController overlay in portrait

查看:92
本文介绍了将UISplitViewController隐藏在肖像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在采用新的UISplitViewController时,我试图将更改更改为使用UISplitViewControllerDisplayModeAutomatic模式时发生的默认行为.

In adopting the new UISplitViewController I'm trying to make a change a default behaviour that occurs when using the UISplitViewControllerDisplayModeAutomatic mode.

在纵向模式下工作时,我希望在用户触发向细节侧的推动时隐藏主要叠加层.默认情况下,叠加层会保留在屏幕上,直到用户在细节侧点击为止.

When working in portrait I want the primary overlay to hide when the user triggers a push to the detail side. By default the overlay remains onscreen until the user taps over on the detail side.

我尝试对委托使用以下内容:

I've tried using the following with the delegate:

- (BOOL)splitViewController:(UISplitViewController *)splitViewController showDetailViewController:(UIViewController *)vc sender:(id)sender
{
    if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) {
        [UIView animateWithDuration:0.3 animations:^{
            splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
        }];
    }
    return NO;
}

这给了我肖像所需的行为,但是这打破了风景模式(我想表现得像UISplitViewControllerDisplayModeAllVisible一样).如果您先按一下然后旋转设备,则左侧仍然是隐藏的(如预期的那样).我找不到合适的贴图位置来重新设置旋转时的首选模式以显示左侧(因为特征集不能用于在iPad上分辨风景还是肖像).

This gives me the desired behavior in portrait, but this breaks landscape mode (which I want to behave like UISplitViewControllerDisplayModeAllVisible). If you've done a push and then rotate the device the left side is still hidden (as expected). I can't find an appriprite place to hook in to re-set the prefered mode on rotation to show the left side (since trait collections can't be used to tell landscape vs portrait on the iPad).

我如何手动触发对叠加层的关闭?

How can I manually trigger a dismissal of the overlay?

重复注释: iOS8 已完全更改了UISplitViewController,因此14年6月之前的所有其他SO答案都可能是错误的(我已经研究了许多答案) ,以防万一)

Dupe note: iOS8 has changed UISplitViewController entirely, so all other SO answers before June '14 are probably wrong (and I've dug through many of them, just incase)

推荐答案

我遇到了与您相同的问题.我正在Xamarin的mono touch平台上执行此操作,但我认为结果将是相同的.

I was having the same problem as you. I am doing this on Xamarin's mono touch platform, but I would think the result would be the same.

就像LaborEtArs所说的那样,将代码移到主视图控制器的prepareForSegue:sender:方法中.然后将其设置为隐藏后,只需将模式设置为自动即可.

Like what LaborEtArs said, move your code to the prepareForSegue:sender: method of the master view controller. Then just set the mode to automatic after you set it to hidden:

if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) {
    splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
    splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
}

以这种方式完成操作后,它不再破坏横向模式.

After doing it this way, it's no longer breaking landscape mode.

这篇关于将UISplitViewController隐藏在肖像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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