swift 中的 addsubview 命令后没有动画 运行
Animation not running after addsubview command in swift
我的应用程序包含一个按钮,它可以使 "spring in" 集合视图动画化,并在您触摸它的外部时隐藏该视图。动画效果很好,直到调用 touchesbegan 函数,然后它才淡入。
我的 touches begin 函数包括 addsubview 命令,这似乎是导致问题的原因。
为什么在读取 addsubview 命令后我的 "spring in" 动画不工作?这是我的约束重置的问题吗?我的动画块每次都被调用。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let bgImage = UIImageView(image: processedImage)
self.viewArray.append(bgImage)
}
func showFilter(){
view.bringSubviewToFront(collectionView)
var collectionViewPos = collectionView.center.x
self.collectionView.center.x = view.frame.width + 300
UIView.animateWithDuration(0.0, delay: 0.0, options: [], animations: { () -> Void in
self.collectionView.alpha = 1
}, completion: { (complete: Bool) in
UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [], animations: { () -> Void in
self.collectionView.center.x = collectionViewPos
self.view.layoutIfNeeded()
}, completion: nil)
return
})
}
我的问题与限制有关。我使用这个问题 的答案来动画约束变化而不是移动。它现在完美地工作。
self.view.bringSubviewToFront(self.collectionView)
constraint.constant = constraint.constant + 300
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [], animations: { () -> Void in
self.view.layoutIfNeeded()
}, completion: nil)
我的应用程序包含一个按钮,它可以使 "spring in" 集合视图动画化,并在您触摸它的外部时隐藏该视图。动画效果很好,直到调用 touchesbegan 函数,然后它才淡入。
我的 touches begin 函数包括 addsubview 命令,这似乎是导致问题的原因。
为什么在读取 addsubview 命令后我的 "spring in" 动画不工作?这是我的约束重置的问题吗?我的动画块每次都被调用。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let bgImage = UIImageView(image: processedImage)
self.viewArray.append(bgImage)
}
func showFilter(){
view.bringSubviewToFront(collectionView)
var collectionViewPos = collectionView.center.x
self.collectionView.center.x = view.frame.width + 300
UIView.animateWithDuration(0.0, delay: 0.0, options: [], animations: { () -> Void in
self.collectionView.alpha = 1
}, completion: { (complete: Bool) in
UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [], animations: { () -> Void in
self.collectionView.center.x = collectionViewPos
self.view.layoutIfNeeded()
}, completion: nil)
return
})
}
我的问题与限制有关。我使用这个问题
self.view.bringSubviewToFront(self.collectionView)
constraint.constant = constraint.constant + 300
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [], animations: { () -> Void in
self.view.layoutIfNeeded()
}, completion: nil)