TouchImageView.m.svn-base
上传用户:huachun008
上传日期:2009-10-03
资源大小:1927k
文件大小:2k
源码类别:

MacOS编程

开发平台:

Objective-C

  1. //
  2. //  TouchImageView.m
  3. //  MultiTouchDemo
  4. //
  5. //  Created by Jason Beaver on 5/29/08.
  6. //  Copyright 2008 Apple Inc.. All rights reserved.
  7. //
  8. #import "TouchImageView.h"
  9. #import "TouchImageView_Private.h"
  10. #include <execinfo.h>
  11. #include <stdio.h>
  12. @implementation TouchImageView
  13. - (id)initWithFrame:(CGRect)frame
  14. {
  15.     if ([super initWithFrame:frame] == nil) {
  16.         return nil;
  17.     }
  18.     originalTransform = CGAffineTransformIdentity;
  19.     touchBeginPoints = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
  20.     self.userInteractionEnabled = YES;
  21.     self.multipleTouchEnabled = YES;
  22.     self.exclusiveTouch = YES;
  23.     return self;
  24. }
  25. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  26.     NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease];
  27.     [currentTouches minusSet:touches];
  28.     if ([currentTouches count] > 0) {
  29.         [self updateOriginalTransformForTouches:currentTouches];
  30.         [self cacheBeginPointForTouches:currentTouches];
  31.     }
  32.     [self cacheBeginPointForTouches:touches];
  33. }
  34. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  35.     CGAffineTransform incrementalTransform = [self incrementalTransformWithTouches:[event touchesForView:self]];
  36.     self.transform = CGAffineTransformConcat(originalTransform, incrementalTransform);
  37. }
  38. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  39.     for (UITouch *touch in touches) {
  40.         if (touch.tapCount >= 2) {
  41.             [self.superview bringSubviewToFront:self];
  42.         }
  43.     }
  44.     [self updateOriginalTransformForTouches:[event touchesForView:self]];
  45.     [self removeTouchesFromCache:touches];
  46.     NSMutableSet *remainingTouches = [[[event touchesForView:self] mutableCopy] autorelease];
  47.     [remainingTouches minusSet:touches];
  48.     [self cacheBeginPointForTouches:remainingTouches];
  49. }
  50. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  51.     [self touchesEnded:touches withEvent:event];
  52. }
  53. - (void)dealloc
  54. {
  55.     CFRelease(touchBeginPoints);
  56.     
  57.     [super dealloc];
  58. }
  59. @end