第一种:
//开始准备动画 [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 * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 300, 100)]; [self.window addSubview:imageView]; //添加动画的图片 NSArray * imageNameArray = @[@"1.png",@"2.png",@"3.png",@"4.png"]; NSMutableArray * imageArray = [[NSMutableArray alloc]init]; for (int i = 0; i<4; i++) { UIImage *image= [UIImage imageNamed:[imageNameArray objectAtIndex:0]]; [imageArray addObject:image]; } //设置播放次数,不设置为无限次 imageView.animationRepeatCount = 10; imageView.animationImages = imageArray; imageView.animationDuration = 2; //开始动画 [imageView startAnimating]; //结束动画 [imageView stopAnimating];
时间: 2024-11-06 23:31:15