在滑动动画上使用 containerview 创建自定义标签栏
create custom tabbar using containerview on swipe animation
我正在使用容器视图创建自定义可滚动标签栏我使用滑动手势在滑动时滚动我想在滑动时做动画我用过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)
任何人都可以告诉我如何做滑动动画或者我哪里做错了吗
isHidden
属性 of UIView
不可设置动画。使用 alpha
属性 获得淡入淡出 in/out
效果。
我正在使用容器视图创建自定义可滚动标签栏我使用滑动手势在滑动时滚动我想在滑动时做动画我用过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)
任何人都可以告诉我如何做滑动动画或者我哪里做错了吗
isHidden
属性 of UIView
不可设置动画。使用 alpha
属性 获得淡入淡出 in/out
效果。