我正在使用containerview创建可滑动的选项卡,我现在有三个选项卡,问题是使用滑动手势,我只能左右滑动,因此如何使用滑动来管理三个选项卡
我已经尝试过使用滑动手势,并且对于两个选项卡而言,它的导航都很完美,但是如何通过左右滑动来处理第三个选项卡,让我向您展示我已经尝试过了
代码
@objc func respondToSwipeGesture(_ sender: UIGestureRecognizer) {
if let swipeGesture = sender as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizer.Direction.right:
UIView.animate(withDuration: 0.3) {
self.viewLineOverDue.center = self.viewLineOverCenter
self.viewLineTodays.center = self.viewLineOverDue.center
self.viewFutureLine.center = self.viewLineOverDue.center
self.lblOverDue.textColor = UIColor(red: 218/255, green: 55/255, blue: 79/255, alpha: 1)
self.lblFuture.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
self.lblTodays.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
self.viewCOnOverdue.isHidden = false
self.viewCOnFuture.isHidden = true
self.viewConTodays.isHidden = true
}
print("right swipe")
case UISwipeGestureRecognizer.Direction.left:
print("leftSwipe")
UIView.animate(withDuration: 0.3) {
self.viewLineTodays.center = self.viewLineTodaysCenter
self.viewLineOverDue.center = self.viewLineTodays.center
self.viewFutureLine.center = self.viewLineTodays.center
self.lblTodays.textColor = UIColor(red: 218/255, green: 55/255, blue: 79/255, alpha: 1)
self.lblFuture.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
self.lblOverDue.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
self.viewCOnOverdue.isHidden = true
self.viewCOnFuture.isHidden = true
self.viewConTodays.isHidden = false
}
default:
break
}
}
}
在viewDidLoad()
let swipeGestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(CustomTabbarViewController.respondToSwipeGesture(_:)))
swipeGestureLeft.direction = UISwipeGestureRecognizer.Direction.left
self.view.addGestureRecognizer(swipeGestureLeft)
let swipeGestureRight = UISwipeGestureRecognizer(target: self, action:#selector(CustomTabbarViewController.respondToSwipeGesture(_:)) )
swipeGestureRight.direction = UISwipeGestureRecognizer.Direction.right
self.view .addGestureRecognizer(swipeGestureRight)
我正在附加我的UI,因此您可以轻松理解
所以我的要求是我想使用滑动手势来滑动三个选项卡
如屏幕快照中所示,我想在两个选项卡上互相导航,就像我的代码一样工作正常,但是如何管理3个选项卡