第一种:
//开始准备动画
[UIView beginAnimations:nil context:nil];
//设置动画的时间
[UIView setAnimationDuration:2.0f];
//设置动画次数
[UIView setAnimationRepeatCount:5];
//设置回放(回到初始位置,默认为NO)
[UIView setAnimationRepeatAutoreverses:YES];
//设置想要动画的视图
redView.frame = self.window.bounds;
redView.backgroundColor = [UIColor blueColor];
//提交动画
[UIView commitAnimations];
第二种:
//设置动画的范围
UIImageView * p_w_picpathView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 300, 100)];
[self.window addSubview:p_w_picpathView];
//添加动画的图片
NSArray * p_w_picpathNameArray = @[@"1.png",@"2.png",@"3.png",@"4.png"];
NSMutableArray * p_w_picpathArray = [[NSMutableArray alloc]init];
for (int i = 0; i<4; i++) {
UIImage *p_w_picpath= [UIImage p_w_picpathNamed:[p_w_picpathNameArray objectAtIndex:0]];
[p_w_picpathArray addObject:p_w_picpath];
}
//设置播放次数,不设置为无限次
p_w_picpathView.animationRepeatCount = 10;
p_w_picpathView.animationImages = p_w_picpathArray;
p_w_picpathView.animationDuration = 2;
//开始动画
[p_w_picpathView startAnimating];
//结束动画
[p_w_picpathView stopAnimating];
转载于:https://blog.51cto.com/8947509/1583442