好吧,有一些Tab栏控制器动画问题试图模仿Apple iTunes离开音乐播放器VC时的动画过渡。现在我有一个媒体栏,它只是一个位于屏幕底部的UIView,每当我选择一个不是音乐播放器视图的标签时动画起来(所以selectedIndex != (viewControllers?.count)!-1
)
这很好,但即使查看其他标签栏动画,我也无法做出类似于iTunes的垂直/挤压动画过渡。这个答案给了我如何像页面一样横向地进行 - iPhone: How to switch tabs with an animation?
但是当它垂直时它不起作用。我基本上想要解除转换,好像该选项卡是模态视图控制器。我有什么:
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
}
但是当前的VC(音乐播放器)在移动并切换selectedIndex之后会快速回到原来的位置。它与标签栏控制器一样,使其所有视图控制器在切换之前处于正确的位置。
如何使用标签栏VC模拟模态消除动画?