我有一个UIImageView名字bigBottle:
bigBottle.image = [UIImage imageNamed:@"fullBootle.png"];
Run Code Online (Sandbox Code Playgroud)
fullBootle.png 是一个装满100%的瓶子.
我需要两个步骤:
动画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%填满)并且没有模糊的结果图像?