tags:

views:

220

answers:

3

Hello,

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

+6  A: 

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];
}
Ben Gottlieb
Sounds really interesting. I will just need to add an overlay to try to mimic the reflect.I am going to test it. Thanks a lot!
AP
Works well. Thanks
AP
A: 

can u please mail me the whole code of this.........

sateesh
A: 

There is a complete example over here. There is a minor error in the downloaded project but otherwise it works great and does exactly what you need.

droussel