使用淡出动画在旋转时关闭 UIPopover [英] close UIPopover on rotation with a fadeout animation

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

问题描述

Apple Pages 和 Numbers 应用程序具有弹出框(用于工具"等),当您旋转设备时会以可爱的淡出效果关闭.我正在尝试重新创建它,但是我的弹出框似乎总是立即关闭,因此旋转的动画看起来并不那么流畅.我目前正在使用:

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];
}

有谁知道实现 Pages/Numbers 中相同效果的最佳方法?

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):

如果用户在弹出框可见时旋转设备,弹出框控制器会隐藏弹出框,然后在旋转结束时再次显示.弹出框控制器尝试为您适当地定位弹出框,但在某些情况下您可能必须再次显示或完全隐藏它.例如,当从条形按钮项显示时,弹出框控制器会自动调整弹出框的位置(可能还有大小)以考虑条形按钮项位置的变化.但是,如果您在旋转期间移除了条形按钮项目,或者如果您从视图中的目标矩形呈现弹出框,则弹出框控制器不会尝试重新定位弹出框.在这些情况下,您必须手动隐藏弹出框或从适当的新位置再次显示它.您可以在用于呈现弹出框的视图控制器的 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: 方法中调用 [toolsPopoverControllerdismissPopoverAnimated:YES],您可以在旋转过渡期间隐藏弹出框时使用动画解除.

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天全站免登陆