本文介绍了iPhone,再现放大镜效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在自定义视图中创建一个可移动的放大镜(如复制和粘贴时所具有的放大镜),以缩放我的视图的一部分.

I would like be able to create a movable magnifier (like the one you have when you copy and paste) in a custom view, for zooming a part of my view.

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

I have no idea on how to start, do you have any idea?

在此先感谢您的帮助:)

Thanks in advance for your help :)

推荐答案

我们在填字游戏中执行此操作.在您的drawRect方法中,遮罩一个圆(使用包含放大镜遮罩"的单色位图),并在其中使用2倍缩放变换绘制主题视图.然后在上面画一个放大镜图像就可以了.

We do this in Crosswords. In your drawRect method, mask off a circle (using a monochrome bitmap containing the 'mask' of your magnifying glass) and draw your subject view in there with a 2x scale transform. Then draw a magnifying glass image over that and you're done.

- (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,再现放大镜效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:44