采用 Cirrostratus 概述的方法,保留其缓存副本,然后在拖动时应用变换来更改图像的大小和/或位置。
(警告,这不是功能/测试代码,但应该可以帮助您入门)
-(UIImage*)addGlowToImage:(UIImage*)imageInput;
{
CGRect newSize = imageInput.bounds;
CGImageRef theImage = imageInput.CGImage;
// expand the size to handle the "glow"
newSize.size.width += 6.0;
newSize.size.height += 6.0;
UIGraphicsBeginImageContext(newSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginTransparencyLayerWithRect(ctx, newSize, NULL);
CGContextClearRect(ctx, newSize);
// you can repeat this process to build glow.
CGContextDrawImage(ctx, newSize, theImage);
CGContextSetAlpha(ctx, 0.2);
CGContextEndTransparencyLayer(ctx);
// draw the original image into the context, offset to be centered;
CGRect centerRect = inputImage.bounds;
centerRect.origin.x += 3.0;
centerRect.origin.y += 3.0;
CGContextDrawImage(ctx, centerRect, theImage);
result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
然后在你的方法中,在缩放时你会做类似的事情:
// assumes UIImage *cachedImage = [self addGlowToImage:origImage]; has been called already.
// assumes ivars for scale exists
CGRect newRect = cachedImage.bounds;
newRect.size.width += scale;
newRect.size.height += scale;
[cachedImage drawInRect:newRect]; // image will be scaled to fill destination rectangle.
一定要看看苹果文档。一个好的起点是Quartz 2D 编程指南 http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html.