Ok, having some Tab bar controller animation problems trying to mimic the animation transition in Apple's iTunes when they leave the music player VC. Right now I have a media bar which is just a UIView that sits on the bottom of the screen and animates up whenever I select a tab that isn't the music player view (so selectedIndex != (viewControllers?.count)!-1
)
This is fine, but even looking at other tab bar animations I cant make something like the vertical/squish animation transition from iTunes. This answer gave me how to do it horizontally like a page - iPhone: How to switch tabs with an animation?
However it doesn't work when you make it vertical. I basically want the dismiss transition as if the tab were a modal view controller. What I have:
func animateToTab(toIndex: Int) {
let tabViewControllers = viewControllers!
let fromView = selectedViewController!.view
let toView = tabViewControllers[toIndex].view
let fromIndex = tabViewControllers.index(of: selectedViewController!)
guard fromIndex != toIndex else {return}
// Add the toView to the tab bar view
fromView?.superview!.addSubview(toView!)
fromView?.superview!.sendSubview(toBack: toView!)
// Disable interaction during animation
view.isUserInteractionEnabled = false
UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0.3, options: UIViewAnimationOptions.curveEaseOut, animations: {
// Slide the views by -offset
fromView?.superview!.center.y += screenSize.height
//toView?.center = CGPoint(x: (toView?.center.x)! - offset, y: (toView?.center.y)!);
}, completion: { finished in
// Remove the old view from the tabbar view.
fromView?.removeFromSuperview()
self.view.isUserInteractionEnabled = true
})
self.selectedIndex = toIndex
}
But the current VC, the music player, snaps back to its original position after it moves and switches the selectedIndex. Its like the tab bar controller makes all its viewcontrollers be in the right position before switching.
How can I mimic a modal dismiss animation with a tab bar VC?