动画反转与重复

 动画的反转

执行与否与放置的位置有关。
若放在动画对象动画动作之前,则执行,否则不执行。
    [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];  //只反转一次

 

posted @ 2014-12-16 20:16  红红de  阅读(270)  评论(0编辑  收藏  举报