An example of a magnifier in iOS

Source: Internet
Author: User

This article implements the magnifier function. The usage is as follows:

1. Import the MagnifierView class to the project. : Http://pan.baidu.com/s/1eUz2Q

ViewController. h

#import 
 
  #import "MagnifierView.h"@interface ViewController : UIViewController@property (strong , nonatomic) MagnifierView* loop;@property (strong , nonatomic) NSTimer* touchTimer;@end
 

ViewController. m

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.        UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"changmen.jpg"]];    image.frame  = CGRectMake(0, 0, 320, 548);    [self.view addSubview:image];}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {        self.touchTimer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(addLoop) userInfo:nil repeats:NO];        if (self.loop == nil) {        self.loop = [[MagnifierView alloc] init];        self.loop.viewToMagnify = self.view;    }        UITouch* touch = [touches anyObject];    self.loop.touchPoint = [touch locationInView:self.view];    [self.loop setNeedsDisplay];    }- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {[self handleAction:touches];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {[self.touchTimer invalidate];self.touchTimer = nil;    self.loop = nil;}- (void)handleAction:(id)timerObj {NSSet *touches = timerObj;UITouch *touch = [touches anyObject];self.loop.touchPoint = [touch locationInView:self.view];[self.loop setNeedsDisplay];}- (void)addLoop {// add the loop to the superview.  if we add it to the view it magnifies, it'll magnify itself!//[self.superview addSubview:loop];[self.loop makeKeyAndVisible];// here, we could do some nice animation instead of just adding the subview...}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.