当 UIViewPropertyAnimator 正在执行动画过程时,如何增加一个值?当我让我的对象运动时,我想在它落在我的屏幕上时增加它的值,但我不确定如何将它与我的 Animator 链接。有什么建议么?以下是我发起的方式
let toTravel = CGFloat(blockSize * newInstance.distanceToTravel()) //checks how far it needs to go.
let frame = CGRect(x: x, y: startY, width: width, height: height)
super.init(frame: frame)
backgroundColor = UIColor.clear
addSubBlocksToView(grid: grid, blockSize: blockSize)
animator = UIViewPropertyAnimator(duration: 10.0, curve: .linear) { [unowned self] in
self.center.y += toTravel // need to calculate CODE this it is a static right now
}
如您所见,行驶我计算的距离需要 10 秒。我想用计数器跟踪它经过的每几个像素(30)。