我在这里使用从另一个答案中获取的代码,但基本上下面是我正在使用的代码。这样做的主要问题是,当我调用它时,它需要 15 秒才能开始,然后需要 15 秒才能完成每个动画。我希望它立即开始!我在这里想念什么?
调用使用
-(void)viewDidLoad {
[self animationLoop: nil finished:nil context:nil];
}
功能
-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:15];
int padding = _Circle1Container.frame.size.width / 2;
// Circle 1
CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width + padding);
CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height + padding);
CGPoint squarePostion = CGPointMake(x, y);
_Circle1Container.center = squarePostion;
[UIView setAnimationDelegate:self]; // as suggested by @Carl Veazey in a comment
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}