iPhone,重现放大镜效果

AP.*_*AP. 19 iphone uiview

我希望能够在自定义视图中创建一个可移动的放大镜(就像你复制和粘贴时那样),用于缩放视图的一部分.

我不知道如何开始,你有什么想法吗?

在此先感谢您的帮助 :)

Ben*_*ieb 16

我们在填字游戏中这样做.在drawRect方法中,屏蔽圆圈(使用包含放大镜"遮罩"的单色位图)并使用2x缩放变换在其中绘制主题视图.然后在上面画一个放大镜图像,你就完成了.

- (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];
}
Run Code Online (Sandbox Code Playgroud)