小编use*_*236的帖子

使用动画从完整的UIImage填充UIImageView的百分比

我有一个UIImageView名字bigBottle:

bigBottle.image =  [UIImage imageNamed:@"fullBootle.png"];
Run Code Online (Sandbox Code Playgroud)

fullBootle.png 是一个装满100%的瓶子.

我需要两个步骤:

  1. 首先用百分比制作一幅图像(比如50%填充) - 也就是说,从底部填充一半的瓶子).
  2. 动画bigBottle从瓶子的下方爬行填充效果到50%填充.我的代码如下:

    CGRect captureRect = CGRectMake(0,22,18,72);
    UIImage *captureImg;
    UIGraphicsBeginImageContext(captureRect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.bigBottle.layer renderInContext:context];
    captureImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.bigBottle.image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(captureImg.CGImage,
    captureRect)];
    CGRect captureRect1 = CGRectMake(0,37,18,72);
    self.bigBottle.frame=CGRectMake(45, 174,18,1);
    CGRect newFrameOfMyView1 = CGRectMake(45,129, 18, 45);
    [UIView animateWithDuration:3.0f
        animations:^{
            self.bigBottle.frame = newFrameOfMyView1;
        }
        completion:^(BOOL finished){
            NSLog( @"done bottle: 1" );
    }];
    
    Run Code Online (Sandbox Code Playgroud)

另一种方法是让这个装瓶的动画更加简单,内存效率更高?我有几十个瓶子随机填充百分比(让我们说瓶子80是20%填满)并且没有模糊的结果图像?

objective-c uiimageview uiimage ios

0
推荐指数
1
解决办法
1879
查看次数

标签 统计

ios ×1

objective-c ×1

uiimage ×1

uiimageview ×1