UIImageView

来源:互联网 发布:免费球球大作战软件 编辑:程序博客网 时间:2024/06/15 05:19

一. UIImageView加载图片的方式

1.imageNamed: 速度快,占内存,所以适合使用频率高的图片;
2.imageWithContentsOfFile/imageWithData: 适合使用频率低的图片;
参考:http://blog.csdn.net/lvxiangan/article/details/26558267


二.UIImageView的简单动画

方法: imageWithContentsOfFile + animation
demo:

    _circleImgV = [[UIImageView alloc]init];    //动画数组    [_circleImgV setAnimationImages:[self getGIFImages]];    _circleImgV.animationDuration = 1.0;    [_contentImgV addSubview:circleImgV];    [_circleImgV mas_makeConstraints:^(MASConstraintMaker *make) {        make.centerX.mas_equalTo(_contentImgV.centerX);        make.centerY.mas_equalTo(_contentImgV.centerY-20);        make.size.mas_equalTo(CGSizeMake(frame.size.width-70,frame.size.width-70));    }];    [_circleImgV startAnimating];//启动动画   //[_circleImgV stopAnimating];   //用于停止动画//获取图片数组-(NSArray *)getGIFImages{    NSMutableString * picName = [NSMutableString string];    for (int i = 1; i < 11; i++) {        //根据gif图片名而定:        [picName appendFormat:@"动画%d#",i];    }    NSArray * picNameArr = [picName componentsSeparatedByString:@"#"];    NSMutableArray * imageArr = [NSMutableArray array];    for (int i = 0; i < 10; i++) {        //UIImage *img = [UIImage imageNamed:picNameArr[i]];        //imageWithContentsOfFile不能加载image.xcassets中的资源!!!        //所以图片必须直接拖到工程目录下        NSString *imgPath = [[NSBundle mainBundle]pathForResource:picNameArr[i] ofType:@"png"];        UIImage *img = [UIImage imageWithContentsOfFile:imgPath];        [imageArr addObject:img];    }    return imageArr;}
原创粉丝点击