Search code examples
ipadanimationuinavigationcontrollerios7uipopovercontroller

UINavigationController pushViewController:animated: exhibits strange animation behavior


I have an existing iOS app I'm porting to iOS 7. The iPad version uses a UINavigationController in a UIPopoverController. The display of the initial view controller works fine. When I push another view controller with pushViewController:animated with animated=YES, the the new controller is animated in from the right as expected, then it acts as if it has been flicked up and bounces back into position. At the same time, the popover controller gets a little bit bigger.

If I turn off animation I still get the resize but not the bounce. But then I also don't get the animation of the presentation of the new view controller.

At this point I'm looking for clues. I'd post code but it's complicated by the fact that this all runs on iPhones and iPads and automatically detects whether the view controller needs to be presented in a new navigation controller, and whether that navigation controller needs to appear in a popover controller. Rather than make it complicated I'm looking for ideas of why this might happen so I can track down the problem.

The same code works perfectly fine in iOS 5 and 6.

It would be interesting to know if anyone is successfully doing this in iOS 7 -- simply presenting a UINavigationController in a UIPopoverController and pushing view controllers without seeing this behavior.


Solution

  • The problem turns out to be contentSizeForViewInPopover.

    Our UINavigationController subclass implemented this method to tell the containing UIPopoverController how big it should be. Works absolute as documented in all versions of iOS before 7. Not only is it deprecated in 7, it causes the problem described above.

    The solution is to return popoverController.contentViewController.view.bounds.size in iOS 7 and re-do all your views so they fit in the popover rather than sizing the popover to handle your view.

    Another solution might be to get rid of the navigation controller and simply dismiss the popover controller and re-display a new one at the new size.

    Thanks for reading along. Someday I'll try to ask a question that someone can answer.