你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 一個iOS下的放大鏡例子

一個iOS下的放大鏡例子

編輯:IOS開發綜合

本文實現了放大鏡功能,具體用法如下

1、將MagnifierView類導入到工程中,在例子中就有的。下載地址: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...
}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved