【发布时间】:2016-07-31 00:14:30
【问题描述】:
我有一个动画,它删除 UI 中的一个圆圈,然后在其他地方重新创建它,但是当我重新创建它时,它比我想要的要小。我不知道为什么它看起来更小了。
let viewsToAnimate = [circleFrame]
UIView.perform(UISystemAnimation.delete, on: viewsToAnimate, options: [], animations: {
}, completion: { finished in
self.circle.removeFromSuperlayer()
self.circleFrame.removeFromSuperview()
self.circleFrame.layer.removeAllAnimations()
self.createCircle()
self.score = self.score + 1
self.scoreLabel.text = "Taps: " + String(self.score)
self.tapsLabel.text = "Taps: " + String(self.initialTaps + self.score)
})
func createCircle() {
let randomX = generateRandomX()
let randomY = generateRandomY()
circleCenter = generateCircleCenter(x: randomX, y: randomY)
circleFrame.frame = CGRect(x: randomX, y: randomY, width: 100, height: 100)
circleFrame.alpha = 1.0
self.view.addSubview(circleFrame)
circle.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 100, height: 100), cornerRadius: 50).cgPath
circle.fillColor = UIColor(red: 0, green: greenValue/255, blue: 0.6, alpha: 1.0).cgColor
circle.strokeColor = UIColor(red: 1, green: greenValue/255, blue: 0, alpha: 1.0).cgColor
circle.lineWidth = 0
circleFrame.layer.addSublayer(circle)
}
我尝试删除所有动画,但它总是显得更小。关于为什么会发生这种情况的任何帮助都会很棒。
这是第一次调用 createCircle() 时的样子。
这是从动画中调用它时的样子。
【问题讨论】:
-
我很难上传前后的照片,但这里有一个 Dropbox 链接。带大点的那张是第一次调用 createCircle() 时的样子,而另一张是从动画中调用它时的样子。 dropbox.com/sh/bccvdfnrjgou2tp/AABZYmswSlwkXimAHG_dQ9tYa?dl=0
-
我正在放入 removeAllAnimations 和 removeFromSuperview 以查看它们是否会修复它,但他们没有。据我所知, createCircle() 并不是每次都创建它。变量 circle 在 viewController 中的所有函数之外调用,因此我可以在创建它们的位置以外的其他函数中编辑它们。每次我重新创建它们时,我都认为它们是从以前的内容中编辑的。
-
如何找到解决办法?
标签: animation swift3 ios10 ios-animations