我正在尝试使一个UIButton随机在屏幕上不同方向移动。下面的代码有点可行。按钮将开始沿着随机路径移动,但它会继续在A点和B点之间来回移动。
如何让它在改变方向时每次都移动到一个新的随机点,而不是简单地来回移动?
谢谢!
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationRepeatAutoreverses:YES];
CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height);
CGPoint squarePostion = CGPointMake(x, y);
button.center = squarePostion;
[UIView commitAnimations];
如何让它在改变方向时每次都移动到一个新的随机点,而不是简单地来回移动?
谢谢!