Reputation: 49693
I'm implementing a custom containment view controller. The child VC's are navigation controllers and are full screen. To perform the transition/animation I'm using:
// controller hierarchy setup
parentVC.addChildViewController(targetVC)
currentVC.willMoveToParentViewController(nil)
// position target
targetVC.view.frame = currentVC.view.frame
targetVC.view.autoresizingMask = .FlexibleHeight | .FlexibleWidth
// swap em
parentVC.transitionFromViewController(currentVC, toViewController: targetVC, duration: 0.3, options: .TransitionCrossDissolve, animations: {}) { (finished) -> Void in
// controller hierarchy complete
self.currentVC.removeFromParentViewController()
self.targetVC.didMoveToParentViewController(self.parentVC)
}
It works fine with the big exception that the navigation bar underlaps the status bar until the animation is complete, at which point it pops into place with the extra 20px in height.
Since the frame is being set before the animation, and the animation does not affect the frame, I'm at a loss... any ideas?
Upvotes: 1
Views: 246
Reputation: 49693
I was able to get the desired effect by ditching transitionFromViewCon...
and just using UIView's animateWithDuration
. Seems like figuring out how to stick with transitionFromViewCon...
would be ideal, but I'll roll with this for now.
// controller hierarchy setup
parentVC.addChildViewController(targetVC)
currentVC.willMoveToParentViewController(nil)
// position target
targetVC.view.alpha = 0
parentVC.view.addSubview(targetVC.view)
// swap em
UIView.animateWithDuration(0.3, animations: { () -> Void in
// crossfade
self.targetVC.view.alpha = 1
self.currentVC.view.alpha = 0
}, { (finished) -> Void in
self.currentVC.view.removeFromSuperview()
// controller hierarchy complete
self.currentVC.removeFromParentViewController()
self.targetVC.didMoveToParentViewController(self.parentVC)
})
Upvotes: 2