我在屏幕右侧滑动或左侧更改标签栏即时切换标签栏之间的滑动手势 如何制作它看起来像滑动到右侧或左侧标签栏而不是立即更改标签栏
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)
}
}
答案 0 :(得分:1)
您可以使用此pod
实现此效果如果要从头开始构建它,则需要子类containerView
。然后将视图控制器(childVCs)放在scrollView
内(仅在水平方向滚动)。