Estoy tratando de animar un UIButton para mover aleatoriamente alrededor de la pantalla en diferentes direcciones. El siguiente código está funcionando. El botón comenzará a moverse a lo largo de un camino al azar, sin embargo, a continuación, sólo continúa moviéndose hacia atrás y adelante entre el punto A y el punto B.Mover un objeto al azar alrededor de la pantalla
[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];
¿Cómo puedo conseguir que se mantienen en movimiento a un nuevo punto al azar cada vez cambia de dirección, en lugar de simplemente moverse hacia adelante y hacia atrás?
Gracias!
El botón sólo se trasladó a punto B y luego parado. – thenameisnick
Es posible que deba agregar [UIView setAnimationDelegate: self]; allí también. –
Funciona muy bien. ¡Gracias! – thenameisnick