当我在屏幕上向右或向左滑动时,我有滑动手势在标签栏之间切换,它改变了我在其中的标签栏 我该怎么做才能让它看起来像是在向右或向左滑动标签栏,而不是立即更改标签栏
class SwipeGesture: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let left = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft))
left.direction = .left
self.view.addGestureRecognizer(left)
let right = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight))
right.direction = .right
self.view.addGestureRecognizer(right)
}
@objc func swipeLeft() {
let total = self.tabBarController!.viewControllers!.count - 1
tabBarController!.selectedIndex = min(total, tabBarController!.selectedIndex + 1)
}
@objc func swipeRight() {
tabBarController!.selectedIndex = max(0, tabBarController!.selectedIndex - 1)
}
}
最佳答案
您可以使用此 pod 实现此效果
如果你想从头开始构建它,你需要继承containerView
。然后将 View Controller (childVC) 放入 scrollView
(仅在水平方向滚动)。
关于ios - 使滑动手势动画化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47105940/