我有一个滑动手势,可以在屏幕右侧或左侧滑动时切换选项卡栏。现在的问题是,如何让它看起来像是向右或向左滑动到另一个选项卡栏,而不是突然切换到另一个选项卡栏。
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)
}
}