【发布时间】:2016-09-01 15:28:57
【问题描述】:
我正在尝试创建一个动画,以给定的延迟将屏幕上的圆圈移动到随机点。
然而,我的问题是当我打电话重复动画时。它将我的圆圈移回原点,并以完全相同的坐标重复该精确动画。有没有办法让我制作一个每次都需要新坐标的重复动画?
startAnimations():
func startAnimations() {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDelay(gameSpeed)
UIView.setAnimationRepeatCount(100)
moveCircle()
UIView.setAnimationDelegate(self)
UIView.setAnimationDidStopSelector(#selector(killFloor))
UIView.commitAnimations()
}
moveCircle():
func moveCircle() {
self.view.layoutIfNeeded()
animator.removeAllBehaviors()
let randomPoint = grabRandomPoint(from: self)
print("Random Point (\(randomPoint.x), \(randomPoint.y))")
circle.center = randomPoint
}
grabRandomPoint():
func grabRandomPoint(from vc: ViewController) -> CGPoint {
// x coordinate between MinX (left) and MaxX (right):
let randomX = randomInRange(Int(CGRectGetMinX(vc.view.frame)), hi: Int(CGRectGetMaxX(vc.view.frame)))
// y coordinate between MinY (top) and MaxY (bottom):
let randomY = randomInRange(Int(CGRectGetMinY(vc.view.frame)), hi: Int(CGRectGetMaxY(vc.view.frame)))
let randomPoint = CGPoint(x: randomX, y: randomY)
return randomPoint
}
【问题讨论】:
-
块。基于。动画片。自从。 IOS。 4.
标签: ios swift xcode animation uiview