IOS模拟动态图 大图和小图动态切换

 

 

 

  NSInteger index = 0;
    for (ONRadioGiftsModel *gift in _gifts) {
        if ([gift.isLost isEqualToString:@"0" ]) {
            _isShow = YES;
         
               UIImageView*gifImageView=[[UIImageView alloc]initWithFrame:CGRectMake(imageViewMargin*(index+1)+giftsImageW*index,imageViewMargin, 50, 50)];
               gifImageView.userInteractionEnabled = YES;
               gifImageView.contentMode=UIViewContentModeScaleAspectFit;
            
                [gifImageView sd_setImageWithURL:[NSURL URLWithString:gift.giftInfo.giftPicPath] completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, NSURL *imageURL) {

//生成小的缩略图
                    UIImage *image3 = [self thumbnailWithImageWithoutScale:image size:CGSizeMake(image.size.width-30, image.size.height-30)];
                    NSArray*gifArray=[[NSArray alloc]initWithObjects:image,image3, nil];
                    gifImageView.animationImages=gifArray;
                    gifImageView.animationDuration=2;
                    gifImageView.animationRepeatCount=MAXFLOAT;
                    [gifImageView startAnimating];
                    
                    UIButton *btn = [[UIButton alloc]initWithFrame:gifImageView.bounds];
                    btn.tag = index;
                    btn.backgroundColor = [UIColor clearColor];
                    [btn addTarget:self action:@selector(giftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
                    [gifImageView addSubview:btn];
                    
                    [self addSubview:gifImageView];
                   
                    
                }];
             index++;
//            UIButton *giftBtn = [[UIButton alloc]initWithFrame:CGRectMake(index*giftBtnW, 0, giftBtnW, self.height)];
//            giftBtn.contentMode = UIControlContentHorizontalAlignmentCenter;
//            giftBtn.tag = index;
//            [giftBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:gift.giftInfo.giftPicPath] forState:UIControlStateNormal];
//            [giftBtn addTarget:self action:@selector(giftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }

posted @ 2016-01-18 15:41  新阳  阅读(757)  评论(0)    收藏  举报