动画的反转
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2]; [UIView setAnimationRepeatAutoreverses:YES]; [UIView setAnimationRepeatCount:2]; imageView.frame = CGRectMake(170, 300, 60, 50); //执行返回一次,然后再回到动画结束的位置,即 (170, 300, 60, 50) [UIView commitAnimations];
若将这两句的位置调换,即
imageView.frame = CGRectMake(170, 300, 60, 50); [UIView setAnimationRepeatCount:2]; [UIView setAnimationRepeatAutoreverses:YES]; //不执行反转
动画的重复要与反转在一起搭配使用才能呈现效果
[UIView setAnimationRepeatCount:2]; //设置动画重复次数要与反转放在一起,否则也不起作用 [UIView setAnimationRepeatAutoreverses:YES]; imageView.frame = CGRectMake(170, 300, 60, 50);
如果分开放,只会反转一次(默认为一次)。
[UIView setAnimationRepeatAutoreverses:YES]; imageView.frame = CGRectMake(170, 300, 60, 50); [UIView setAnimationRepeatCount:2]; //只反转一次
原文:http://www.cnblogs.com/hyhl23/p/4167953.html