我正在使用容器视图创建自定义可滚动标签栏,我在屏幕上滑动时使用了滑动手势,我想在屏幕上进行动画处理,我使用了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)
任何人都可以告诉我如何制作动画或我做错了什么
答案 0 :(得分:0)
isHidden
的 UIView
属性无法设置动画。使用alpha
属性可获得淡入淡出的in/out
效果。