我知道你可以用UIImageView来做这件事,但是可以用UIImageView来做吗?我想让UIImageView的animation images数组属性成为相同图像但不透明度不同的array.思想?
我知道你可以用UIImageView来做这件事,但是可以用UIImageView来做吗?我想让UIImageView的animation images数组属性成为相同图像但不透明度不同的array.思想?
我只是需要这样做,但我认为史蒂文的解决方案会很慢.这将有望使用显卡硬件.在UIImage上创建类别:
- (UIImage *)imageByApplyingAlpha:(CGFloat) alpha {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextSetAlpha(ctx, alpha);
CGContextDrawImage(ctx, area, self.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}