TouchImageView.m
上传用户:huachun008
上传日期:2009-10-03
资源大小:1927k
文件大小:2k
- //
- // TouchImageView.m
- // MultiTouchDemo
- //
- // Created by Jason Beaver on 5/29/08.
- // Copyright 2008 Apple Inc.. All rights reserved.
- //
- #import "TouchImageView.h"
- #import "TouchImageView_Private.h"
- #include <execinfo.h>
- #include <stdio.h>
- @implementation TouchImageView
- - (id)initWithFrame:(CGRect)frame
- {
- if ([super initWithFrame:frame] == nil) {
- return nil;
- }
- originalTransform = CGAffineTransformIdentity;
- touchBeginPoints = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
- self.userInteractionEnabled = YES;
- self.multipleTouchEnabled = YES;
- self.exclusiveTouch = YES;
- return self;
- }
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease];
- [currentTouches minusSet:touches];
- if ([currentTouches count] > 0) {
- [self updateOriginalTransformForTouches:currentTouches];
- [self cacheBeginPointForTouches:currentTouches];
- }
- [self cacheBeginPointForTouches:touches];
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- CGAffineTransform incrementalTransform = [self incrementalTransformWithTouches:[event touchesForView:self]];
- self.transform = CGAffineTransformConcat(originalTransform, incrementalTransform);
- }
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- for (UITouch *touch in touches) {
- if (touch.tapCount >= 2) {
- [self.superview bringSubviewToFront:self];
- }
- }
- [self updateOriginalTransformForTouches:[event touchesForView:self]];
- [self removeTouchesFromCache:touches];
- NSMutableSet *remainingTouches = [[[event touchesForView:self] mutableCopy] autorelease];
- [remainingTouches minusSet:touches];
- [self cacheBeginPointForTouches:remainingTouches];
- }
- - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
- [self touchesEnded:touches withEvent:event];
- }
- - (void)dealloc
- {
- CFRelease(touchBeginPoints);
-
- [super dealloc];
- }
- @end