close UIPopover on rotation with a fadeout animation

后端 未结 2 1054
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 06:50

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

相关标签:
2条回答
  • 2020-12-20 07:36

    This worked for me by calling dismissPopoverAnimated: from willRotateToInterfaceOrientation:duration:.

    0 讨论(0)
  • 2020-12-20 07:56

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

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题