首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

放大镜成效(二)

2012-07-05 
放大镜效果(二)以前也写过一篇:放大镜效果,现在,提供另一种解决方案。?@interface MagnifierView : UIWindo

放大镜效果(二)

以前也写过一篇:放大镜效果,现在,提供另一种解决方案。

?

@interface MagnifierView : UIWindow {UIView *viewToMagnify;CGPoint touchPoint;}@property (nonatomic, retain) UIView *viewToMagnify;@property (assign) CGPoint touchPoint;@end

#import "MagnifierView.h"#import <QuartzCore/QuartzCore.h>@implementation MagnifierView@synthesize viewToMagnify, touchPoint;- (id)initWithFrame:(CGRect)frame {if (self = [super initWithFrame:CGRectMake(0, 0, 80, 80)]) {self.layer.borderColor = [[UIColor lightGrayColor] CGColor];self.layer.borderWidth = 3;self.layer.cornerRadius = 40;self.layer.masksToBounds = YES;self.windowLevel = UIWindowLevelAlert;}return self;}- (void)setTouchPoint:(CGPoint)pt {touchPoint = pt;self.center = CGPointMake(pt.x, pt.y-10);}- (void)drawRect:(CGRect)rect {CGContextRef context = UIGraphicsGetCurrentContext();CGContextTranslateCTM(context, self.frame.size.width * 0.5, self.frame.size.height * 0.5);CGContextScaleCTM(context, 1.5, 1.5);CGContextTranslateCTM(context, -1 * (touchPoint.x), -1 * (touchPoint.y));[self.viewToMagnify.layer renderInContext:context];}- (void)dealloc {[viewToMagnify release];[super dealloc];}@end

#import <UIKit/UIKit.h>#import "MagnifierView.h"@interface TouchReader : UIView {NSTimer *touchTimer;MagnifierView *loop;}@property (nonatomic, retain) NSTimer *touchTimer;- (void)addLoop;- (void)handleAction:(id)timerObj;@end

#import "TouchReader.h"#import "MagnifierView.h"@implementation TouchReader@synthesize touchTimer;- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {self.clipsToBounds = NO;self.touchTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(addLoop) userInfo:nil repeats:NO];if(loop == nil){loop = [[MagnifierView alloc] init];loop.viewToMagnify = self;}UITouch *touch = [touches anyObject];loop.touchPoint = [touch locationInView: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;[loop release];loop = nil;}- (void)addLoop {[loop makeKeyAndVisible];}- (void)handleAction:(id)timerObj {NSSet *touches = timerObj;UITouch *touch = [touches anyObject];loop.touchPoint = [touch locationInView:self];[loop setNeedsDisplay];}- (void)dealloc {[loop release];loop = nil;[super dealloc];}@end

热点排行