在滑动动画上使用containerview创建自定义标签栏

时间:2018-11-26 06:26:06

标签: ios swift uiviewanimation uiswipegesturerecognizer

我正在使用容器视图创建自定义可滚动标签栏,我在屏幕上滑动时使用了滑动手势,我想在屏幕上进行动画处理,我使用了UIview.Animate,但是我无法获得动画效果,让我向您展示我的代码

 @objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
        if let swipeGesture = gesture as? UISwipeGestureRecognizer {
            switch swipeGesture.direction {
            case UISwipeGestureRecognizer.Direction.right:
                print("Swiped right")
                UIView.animate(withDuration: 0.3) {
                    self.viewG1.isHidden = false
                    self.viewG2.isHidden = false

                    self.viewC1.isHidden = true
                    self.viewC2.isHidden = true

                    self.secondContainView.isHidden = true
                    self.firstContainewView.isHidden = false

                }
            case UISwipeGestureRecognizer.Direction.left:
                print("Swiped left")
                UIView.animate(withDuration: 0.3) {
                    self.viewG1.isHidden = true
                    self.viewG2.isHidden = true
                    self.viewC1.isHidden = false
                    self.viewC2.isHidden = false
                    self.firstContainewView.isHidden = true
                    self.secondContainView.isHidden = false
                }
            default:
                break
            }
        }
    }

viewDidLoad()中,我编写了这段代码

  let swipe = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
        swipe.direction = UISwipeGestureRecognizer.Direction.right
        self.view.addGestureRecognizer(swipe)

任何人都可以告诉我如何制作动画或我做错了什么

1 个答案:

答案 0 :(得分:0)

isHidden

UIView属性无法设置动画。使用alpha属性可获得淡入淡出的in/out效果。