Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone, reproduce the magnifier effect

Tags:

iphone

uiview

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 :)

like image 223
AP. Avatar asked Jan 08 '10 21:01

AP.


People also ask

Does iPhone have a built-in Magnifier?

The iPhone has a built-in magnifying glass app. Unlike the flashlight app, however, it's an option you need to turn on in settings.

What is iPhone Magnifier?

Magnifier uses your iPhone's built-in camera to enlarge objects or text so you can view them more easily. Credit: Screenshot: Apple. The app allows you to increase the zoom level and turn on the flashlight to better display objects and text. You can also adjust the image brightness and contrast, and apply color filters ...


1 Answers

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];
}
like image 104
Ben Gottlieb Avatar answered Oct 05 '22 08:10

Ben Gottlieb