ios怎样在imageView实现动画

ios怎样在imageView实现动画,第1张

//为图片设置动态

self.imageView.animationImages = animateArray

//为动画设置持续时间

self.imageView.animationDuration = 3.0

//创建imageView

self.imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0, 40, 320, 260)]

//把图片添加到动态数组

NSMutableArray * animateArray = [[NSMutableArrayalloc]initWithCapacity:20] [animateArray addObject:[UIImage imageNamed:@"t1.png"]]

[animateArray addObject:[UIImage imageNamed:@"t2.png"]]

[animateArray addObject:[UIImage imageNamed:@"t3.png"]]

[animateArray addObject:[UIImage imageNamed:@"t4.png"]]

[animateArray addObject:[UIImage imageNamed:@"t5.png"]]

[animateArray addObject:[UIImage imageNamed:@"t6.png"]]

[animateArray addObject:[UIImage imageNamed:@"t7.png"]]

[animateArray addObject:[UIImage imageNamed:@"t8.png"]]

[animateArray addObject:[UIImage imageNamed:@"t9.png"]]

[animateArray addObject:[UIImage imageNamed:@"t10.png"]]

[animateArray addObject:[UIImage imageNamed:@"t11.png"]]

[animateArray addObject:[UIImage imageNamed:@"t12.png"]]

[animateArray addObject:[UIImage imageNamed:@"t13.png"]]

[animateArray addObject:[UIImage imageNamed:@"t14.png"]]

[animateArray addObject:[UIImage imageNamed:@"t15.png"]]

[animateArray addObject:[UIImage imageNamed:@"t16.png"]]

[animateArray addObject:[UIImage imageNamed:@"t17.png"]]

[animateArray addObject:[UIImage imageNamed:@"t18.png"]]

[animateArray addObject:[UIImage imageNamed:@"t19.png"]]

[animateArray addObject:[UIImage imageNamed:@"t20.png"]]

//开始播放动画

[self.imageView startAnimating]

//为默认的无限循环

self.imageView.animationRepeatCount = 0 [self.view addSubview:self.imageView]

//下载图片

-(UIImage *) getImageFromURL:(NSString *)fileURL {

NSLog(@"执行图片下载函数")

UIImage * result

NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]

result = [UIImage imageWithData:data]

//下面是一句话搞定,上面是分开来做得。

//UIImage * result = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]]

return result

}

//下面是定义ImageView的方法

-(void) initImageView{

NSString * urlWeb=@"xxxxxxx"

UIImageView * imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0 , 200, 400)]

imageView.backgroundColor=[UIColor blueColor]

//两种方法,用imageNamed可以把图片放入内存,重复使用。但是太多会挂掉,一般重复使用的图片用imageNamed

[imageView setImage:[self getImageFromURL:urlWeb]]

//[imageView setImage:[UIImage imageNamed:@"desc_bn.png"]]

[self.view addSubview:imageView]

}

最后在viewDidLoad函数里面调用initImageView方法就行了。

注意:我把所有的函数内容不分函数,直接写进viewDidLoad里面,速度特别慢。。所以记得分开写。估计和机制有关。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/7775310.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存