gpt4 book ai didi

ios - swift 中的 addsubview 命令后动画未运行

转载 作者:行者123 更新时间:2023-11-30 13:29:15 29 4
gpt4 key购买 nike

我的应用程序包含一个按钮,该按钮可以为“弹出” Collection View 设置动画,并在您触摸其外部时隐藏该 View 。动画效果很好,直到调用touchesbegan函数,然后它才会淡入。

我的触摸开始功能包括 addsubview 命令,这似乎是导致问题的原因。 为什么在读取 addsubview 命令后我的“spring in”动画不起作用?这是我重置约束的问题吗?我的动画 block 每次都会被调用。

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

最佳答案

我的问题与限制有关。我使用了这个问题的答案How do I animate a NSLayoutConstraint in Swift?对约束变化而不是运动进行动画处理。现在可以完美运行了。

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)

关于ios - swift 中的 addsubview 命令后动画未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760247/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com