我希望能够在自定义 View 中创建一个可移动的放大镜(就像复制和粘贴时所使用的放大镜),用于缩放 View 的一部分。
我不知道如何开始,你有什么想法吗?
预先感谢您的帮助:)
最佳答案
我们在填字游戏中做到这一点。在您的drawRect方法中,遮盖一个圆圈(使用包含放大镜“ mask ”的单色位图)并使用2倍比例变换在其中绘制主题 View 。然后在上面画一个放大镜图像就完成了。
- (void) drawRect: (CGRect) rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bounds = self.bounds;
CGImageRef mask = [UIImage imageNamed: @"loupeMask"].CGImage;
UIImage *glass = [UIImage imageNamed: @"loupeImage"];
CGContextSaveGState(context);
CGContextClipToMask(context, bounds, mask);
CGContextFillRect(context, bounds);
CGContextScaleCTM(context, 2.0, 2.0);
//draw your subject view here
CGContextRestoreGState(context);
[glass drawInRect: bounds];
}
关于iPhone,重现放大镜效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2093322/