关闭UIPopover与渐变动画旋转 [英] close UIPopover on rotation with a fadeout animation

查看:262
本文介绍了关闭UIPopover与渐变动画旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple Pages和Numbers应用程序具有popovers(用于工具等),当您旋转设备时,它们带有可爱的淡出效果。我试图重新创建这个,但我的popovers总是似乎关闭瞬间,所以旋转的动画看起来不那么光滑。我目前正在使用:

The Apple Pages and Numbers apps have popovers (for "tools" etc) that close with a lovely fade out effect when you rotate the device. I'm trying to recreate this, but my popovers always seem to close instantly, so the animation of the rotation doesn't look quite as smooth. I'm currently using:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{    
    [toolsPopoverController dismissPopoverAnimated:YES];
}

有没有人知道最好的方法来实现页面/数字?

Does anyone know the best way to achieve the same effect seen in Pages/Numbers?

感谢!

推荐答案

根据UIPopoverController (强调已添加):

Based on the documentation for the UIPopoverController (emphasis added):


如果用户在弹出窗口可见时旋转设备, popover控制器会隐藏popover,然后在旋转结束时再次显示。 popover控制器尝试为您适当地定位popover,但在某些情况下,您可能必须再次显示或完全隐藏。例如,当从条形按钮项目显示时,弹出控制器自动调整弹出框的位置(以及潜在地大小)以考虑到对条形按钮项目的位置的改变。但是,如果在旋转期间删除了bar按钮项,或者如果您在视图中显示了目标矩形中的popover,则popover控制器不会尝试重新定位popover。在这些情况下,您必须手动隐藏弹出窗口或从适当的新位置重新显示。您可以在用于显示弹出框的视图控制器的 didRotateFromInterfaceOrientation:方法中执行此操作。

If the user rotates the device while a popover is visible, the popover controller hides the popover and then shows it again at the end of the rotation. The popover controller attempts to position the popover appropriately for you but you may have to present it again or hide it altogether in some cases. For example, when displayed from a bar button item, the popover controller automatically adjusts the position (and potentially the size) of the popover to account for changes to the position of the bar button item. However, if you remove the bar button item during the rotation, or if you presented the popover from a target rectangle in a view, the popover controller does not attempt to reposition the popover. In those cases, you must manually hide the popover or present it again from an appropriate new position. You can do this in the didRotateFromInterfaceOrientation: method of the view controller that you used to present the popover.

看起来,通过在 willAnimateRotationToInterfaceOrientation:方法中调用[toolsPopoverController dismissPopoverAnimated:YES],您会在旋转过渡期间隐藏popover时使用动画来关闭。

It would appear that by calling [toolsPopoverController dismissPopoverAnimated:YES] in the willAnimateRotationToInterfaceOrientation: method, you are dismissing with an animation while the popover is hidden during the rotation transition.

如果您调用 didRotateFromInterfaceOrientation:方法中的dismissPopoverAnimated:YES方法,则弹出框位于新位置的默认行为应在

If you call the dismissPopoverAnimated:YES method in the didRotateFromInterfaceOrientation: method instead, the default behavior with the popover in the new position should present before the dismiss animation is invoked.

如果默认动画仍然不是您要查找的点,我将创建一个自定义动画块并管理淡出或重新 - 明确地满足您的需求。

If the default animation is still not what you are looking for at this point, I would create a custom animation block and manage the fadeout or re-sizing explicitly to meet your desired needs.

这篇关于关闭UIPopover与渐变动画旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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