ios - 使滑动手势动画化

标签 ios swift xcode animation uiswipegesturerecognizer

当我在屏幕上向右或向左滑动时,我有滑动手势在标签栏之间切换,它改变了我在其中的标签栏 我该怎么做才能让它看起来像是在向右或向左滑动标签栏,而不是立即更改标签栏

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)
    }


}

最佳答案

您可以使用此 pod 实现此效果

如果你想从头开始构建它,你需要继承containerView。然后将 View Controller (childVC) 放入 scrollView(仅在水平方向滚动)。

关于ios - 使滑动手势动画化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47105940/

相关文章:

ios - 在 UILabel 中显示数字、运算符号和总和

xcode - 无法在 ios8 中的 Whatsapp 上共享 url 链接

javascript - jQuery Mobile 点击事件触发 vclick

ios - IBOutletCollection 中不同对象的框架返回空

ios - 错误 Assets 目录编译器错误

ios - Xcode Today Extension 卡在 "Failed to inherit CoreMedia permissions"错误

ios - 如何将 GMSCircle 的边界与 google maps SDK 相匹配以完全显示在 map 上?

ios - 如何在iOS中拖动图像时将图像重叠在另一个图像上?

ios - 使用单个数组内容在 3 个 UIButton 中随机显示图像

swift - 为什么 NSURL 不接受包含引号或大括号的有效字符串?