Ios 使用随机坐标重复动画
我正在尝试创建一个动画,在给定的延迟时间内围绕屏幕移动一个圆到随机点 然而,我的问题是,当我调用以重复动画时。它将我的圆移回原点,并使用完全相同的坐标重复该精确动画。有没有一种方法可以让我重复动画,每次都需要新的坐标 startAnimations(): moveCircle(): 抓取随机点():Ios 使用随机坐标重复动画,ios,swift,xcode,animation,uiview,Ios,Swift,Xcode,Animation,Uiview,我正在尝试创建一个动画,在给定的延迟时间内围绕屏幕移动一个圆到随机点 然而,我的问题是,当我调用以重复动画时。它将我的圆移回原点,并使用完全相同的坐标重复该精确动画。有没有一种方法可以让我重复动画,每次都需要新的坐标 startAnimations(): moveCircle(): 抓取随机点(): 你好,我一直在研究你的问题,这是我发现的,检查这段代码,这段代码永远不会停止,但你可以定义一个执行次数的变量 func startAnimations() { UIView
你好,我一直在研究你的问题,这是我发现的,检查这段代码,这段代码永远不会停止,但你可以定义一个执行次数的变量
func startAnimations() {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDelay(0.5)
moveCircle()
UIView.setAnimationDelegate(self)
UIView.setAnimationDidStopSelector(#selector(self.startAnimations))
UIView.commitAnimations()
}
func moveCircle() {
self.view.layoutIfNeeded()
//animator.removeAllBehaviors()
let randomPoint = grabRandomPoint(from: self)
print("Random Point (\(randomPoint.x), \(randomPoint.y))")
objectToMove.center = randomPoint
}
func grabRandomPoint(from vc: ViewController) -> CGPoint {
// x coordinate between MinX (left) and MaxX (right):
let randomX = randomIntBewtween(Int(CGRectGetMinX(vc.view.frame)), max: Int(CGRectGetMaxX(vc.view.frame)))
// y coordinate between MinY (top) and MidY (middle):
let randomY = randomIntBewtween(Int(CGRectGetMinY(vc.view.frame)), max: Int(CGRectGetMidY(vc.view.frame)))
let randomPoint = CGPoint(x: randomX, y: randomY)
return randomPoint
}
这是我的代码,用来找出
func randomIntBewtween(min : Int, max : Int) ->Int
{
let randomNumber = arc4random_uniform(UInt32(max) - UInt32(min)) + UInt32(min)
return Int(randomNumber)
}
我希望这对您有所帮助您好,我一直在研究您的问题,这是我发现的,检查此代码,此代码将永不停止,但您可以定义一个带有执行次数的变量
func startAnimations() {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDelay(0.5)
moveCircle()
UIView.setAnimationDelegate(self)
UIView.setAnimationDidStopSelector(#selector(self.startAnimations))
UIView.commitAnimations()
}
func moveCircle() {
self.view.layoutIfNeeded()
//animator.removeAllBehaviors()
let randomPoint = grabRandomPoint(from: self)
print("Random Point (\(randomPoint.x), \(randomPoint.y))")
objectToMove.center = randomPoint
}
func grabRandomPoint(from vc: ViewController) -> CGPoint {
// x coordinate between MinX (left) and MaxX (right):
let randomX = randomIntBewtween(Int(CGRectGetMinX(vc.view.frame)), max: Int(CGRectGetMaxX(vc.view.frame)))
// y coordinate between MinY (top) and MidY (middle):
let randomY = randomIntBewtween(Int(CGRectGetMinY(vc.view.frame)), max: Int(CGRectGetMidY(vc.view.frame)))
let randomPoint = CGPoint(x: randomX, y: randomY)
return randomPoint
}
这是我的代码,用来找出
func randomIntBewtween(min : Int, max : Int) ->Int
{
let randomNumber = arc4random_uniform(UInt32(max) - UInt32(min)) + UInt32(min)
return Int(randomNumber)
}
我希望这有助于您阻止。基于。动画自从网间网操作系统。4.封锁。基于。动画自从网间网操作系统。4.我的问题是消除所有行为吗?我的问题是消除所有行为吗?
func randomIntBewtween(min : Int, max : Int) ->Int
{
let randomNumber = arc4random_uniform(UInt32(max) - UInt32(min)) + UInt32(min)
return Int(randomNumber)
}