我有滑动手势,当我在屏幕上向右或向左滑动时,它会在标签栏之间切换。它会改变标签栏,我如何才能让它看起来像是滑向右边或左边的标签栏,而不是直接改变标签栏
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)
}
}发布于 2017-11-04 11:48:30
您可以使用此pod来实现此效果
如果你想从头开始构建,你需要继承containerView的子类。然后将视图控制器(子in )放入scrollView中(仅在水平方向滚动)。
https://stackoverflow.com/questions/47105940
复制相似问题