在我的项目中,我启用了一个名为'SwipeableTabBarController'的coacopods。这些允许我的选项卡栏视图控制器检测平移手势并在选项卡之间切换。我还编写了一些代码来检测滑动手势,这允许用户隐藏标签栏。问题:即使用户直接点击栏项,我的应用也会有幻灯片动画。有什么办法可以解决这个问题吗?我感谢任何帮助!
已尝试在检测到点击时禁用轻扫和平移手势。但是平移手势不在我的手势数组中。
使用isSwipeEnabled = false
禁用滑动功能。默认情况下,它在 SwipeableTabBarController
中设置为 true
更新:
由于您正在寻找没有SwipeableTabBarController
库提供的动画的解决方案,但仍需要滑动功能。以下是使用默认UITabBarController
执行此操作的方法。
第 1 步:创建一个默认UITabBarController
和 2 个视图控制器,让我们称它们为 ViewController_1
和ViewController_2
第 2 步:为每个ViewController
创建一个类,并在ViewController_1
和ViewController_2
的ViewDidLoad()
方法中添加这些行。
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
swipeRight.direction = UISwipeGestureRecognizer.Direction.right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
swipeLeft.direction = UISwipeGestureRecognizer.Direction.left
self.view.addGestureRecognizer(swipeLeft)
}
然后在每次在两个类中检测到滑动时添加此功能。
@objc func swiped(_ gesture: UISwipeGestureRecognizer) {
if gesture.direction == .left {
if (self.tabBarController?.selectedIndex)! < 2
{
self.tabBarController?.selectedIndex += 1
}
} else if gesture.direction == .right {
if (self.tabBarController?.selectedIndex)! > 0 {
self.tabBarController?.selectedIndex -= 1
}
}
}
这将使您能够滑动并导航到不同的视图控制器,也可以使用Tabbar
按钮进行导航。
希望这有帮助。
您可以在点击操作中使用 POD isSwipeEnabled = false
的属性
当您点击标签栏项目时,它将禁用滚动动画。