ios手勢識別

使用手勢識別

六種手勢識別(繼承于UIGestureRecongnizer基類):

UITapGestureRecongnizer--檢測view上的單擊操作

UIPinchGestureRecongnizer--檢測view上兩個手指的縮放操作

UIPanGestureRecongnizer--檢測view的拖拽操作

UISwipeGestureRecongnizer--檢測view的輕劃操作

UIRotationGestureRecongnizer--檢測view的旋轉操作

UILongPressGestureRecongnizer-檢測view上的長按操作

UITapGestureRecongnizer檢測view上的單擊操作

新建Empty Application項目唆貌,在xib中添加ImageView控件滑潘,Mode為Aspect Fit,選中User Interaction Enabled和Multiple Touch

HomeViewController.h

#import

@interface HomeViewController : UIViewController

@property (retain, nonatomic) IBOutlet UIImageView *imageView;

@end

HomeViewController.m

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

UIPinchGestureRecongnizer檢測view上兩個手指的縮放操作

HomeViewController.m

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat lastScaleValue = 1;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureHandler:)];

[imageView addGestureRecognizer:pinchGesture];

[pinchGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (IBAction)pinchGestureHandler:(UIGestureRecognizer *)sender{

CGFloat scaleValue = [(UIPinchGestureRecognizer *)sender scale];

//如果手指做放大操作,scaleValue的值大于等于1锨咙;如果手指是縮小操作语卤,scaleValue的值小于1

if (scaleValue > 1) {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue + (scaleValue-1), lastScaleValue + (scaleValue-1));

}else {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue * scaleValue, lastScaleValue * scaleValue);

}

//用戶的手指離開了屏幕,將比例值記錄在lastScaleValue 變量中

if (sender.state == UIGestureRecognizerStateEnded) {

if (scaleValue > 1) {

lastScaleValue += (scaleValue - 1);

}else {

lastScaleValue += scaleValue;

}

}

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

UIRotationGestureRecongnizer檢測view的旋轉操作

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat lastScaleValue = 1;

CGFloat rotationValue;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureHandler:)];

[imageView addGestureRecognizer:pinchGesture];

[pinchGesture release];

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureHandler:)];

[imageView addGestureRecognizer:rotationGesture];

[rotationGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (IBAction)pinchGestureHandler:(UIGestureRecognizer *)sender{

CGFloat scaleValue = [(UIPinchGestureRecognizer *)sender scale];

if (scaleValue > 1) {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue + (scaleValue-1), lastScaleValue + (scaleValue-1));

}else {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue * scaleValue, lastScaleValue * scaleValue);

}

if (sender.state == UIGestureRecognizerStateEnded) {

if (scaleValue > 1) {

lastScaleValue += (scaleValue - 1);

}else {

lastScaleValue += scaleValue;

}

}

}

- (IBAction)rotationGestureHandler:(UIGestureRecognizer *)sender{

CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];

CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + rotationValue);

sender.view.transform = transform;

if (sender.state == UIGestureRecognizerStateEnded) {

rotationValue += rotation;

}

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

UIPanGestureRecongnizer檢測view的拖拽操作

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat lastScaleValue = 1;

CGFloat rotationValue;

CGPoint positionValue;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureHandler:)];

[imageView addGestureRecognizer:pinchGesture];

[pinchGesture release];

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureHandler:)];

[imageView addGestureRecognizer:rotationGesture];

[rotationGesture release];

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];

[imageView addGestureRecognizer:panGesture];

[panGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (IBAction)pinchGestureHandler:(UIGestureRecognizer *)sender{

CGFloat scaleValue = [(UIPinchGestureRecognizer *)sender scale];

if (scaleValue > 1) {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue + (scaleValue-1), lastScaleValue + (scaleValue-1));

}else {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue * scaleValue, lastScaleValue * scaleValue);

}

if (sender.state == UIGestureRecognizerStateEnded) {

if (scaleValue > 1) {

lastScaleValue += (scaleValue - 1);

}else {

lastScaleValue += scaleValue;

}

}

}

- (IBAction)rotationGestureHandler:(UIGestureRecognizer *)sender{

CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];

CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + rotationValue);

sender.view.transform = transform;

if (sender.state == UIGestureRecognizerStateEnded) {

rotationValue += rotation;

}

}

- (IBAction)panGestureHandler:(UIGestureRecognizer *)sender{

CGPoint position = [(UIPanGestureRecognizer *)sender translationInView:imageView];

sender.view.transform = CGAffineTransformMakeTranslation(position.x + position.x,

position.y + position.y);

if (sender.state == UIGestureRecognizerStateEnded) {

positionValue.x += position.x;

positionValue.y += position.y;

}

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

UISwipeGestureRecongnizer檢測view的輕劃操作

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat lastScaleValue = 1;

CGFloat rotationValue;

CGPoint positionValue;

NSArray *images;

int imageIndex = 0;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureHandler:)];

[imageView addGestureRecognizer:pinchGesture];

[pinchGesture release];

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureHandler:)];

[imageView addGestureRecognizer:rotationGesture];

[rotationGesture release];

/*注釋panGesture的拖拽操作酪刀,否則劃動和拖拽操作會產(chǎn)生混淆

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];

[imageView addGestureRecognizer:panGesture];

[panGesture release];

*/

images = [[NSArray alloc] initWithObjects:@"iphone.png", @"mm.jpg", @"avatar.png", nil];

//默認情況下是向右的手勢劃動

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureHandler:)];

[imageView addGestureRecognizer:swipeGesture];

[swipeGesture release];

//定義向左的手勢劃動

UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureHandler:)];

swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;

[imageView addGestureRecognizer:swipeLeftGesture];

[swipeLeftGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (IBAction)pinchGestureHandler:(UIGestureRecognizer *)sender{

CGFloat scaleValue = [(UIPinchGestureRecognizer *)sender scale];

if (scaleValue > 1) {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue + (scaleValue-1), lastScaleValue + (scaleValue-1));

}else {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue * scaleValue, lastScaleValue * scaleValue);

}

if (sender.state == UIGestureRecognizerStateEnded) {

if (scaleValue > 1) {

lastScaleValue += (scaleValue - 1);

}else {

lastScaleValue += scaleValue;

}

}

}

- (IBAction)rotationGestureHandler:(UIGestureRecognizer *)sender{

CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];

CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + rotationValue);

sender.view.transform = transform;

if (sender.state == UIGestureRecognizerStateEnded) {

rotationValue += rotation;

}

}

- (IBAction)panGestureHandler:(UIGestureRecognizer *)sender{

CGPoint position = [(UIPanGestureRecognizer *)sender translationInView:imageView];

sender.view.transform = CGAffineTransformMakeTranslation(position.x + position.x,

position.y + position.y);

if (sender.state == UIGestureRecognizerStateEnded) {

positionValue.x += position.x;

positionValue.y += position.y;

}

}

- (IBAction)swipeGestureHandler:(UIGestureRecognizer *)sender{

UISwipeGestureRecognizerDirection direction =[(UISwipeGestureRecognizer *)sender direction];

switch (direction) {

case UISwipeGestureRecognizerDirectionUp:

NSLog(@"向上劃動");

break;

case UISwipeGestureRecognizerDirectionDown:

NSLog(@"向下劃動");

break;

case UISwipeGestureRecognizerDirectionLeft:

imageIndex++;

break;

case UISwipeGestureRecognizerDirectionRight:

imageIndex--;

break;

default:

break;

}

imageIndex = (imageIndex < 0) ? ([images count] - 1):imageIndex % [images count];

imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];

}

- (void)dealloc {

[images release];

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

UILongPressGestureRecongnizer檢測view上的長按操作

添加UIActionSheetDelegate協(xié)議

HomeViewController.h

#import

@interface HomeViewController : UIViewController

{}

@property (retain, nonatomic) IBOutlet UIImageView *imageView;

@end

HomeViewController.m

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat lastScaleValue = 1;

CGFloat rotationValue;

CGPoint positionValue;

NSArray *images;

int imageIndex = 0;

- (void)viewDidLoad

{

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];

tapGesture.numberOfTapsRequired = 2;

[imageView addGestureRecognizer:tapGesture];

[tapGesture release];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureHandler:)];

[imageView addGestureRecognizer:pinchGesture];

[pinchGesture release];

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureHandler:)];

[imageView addGestureRecognizer:rotationGesture];

[rotationGesture release];

/*注釋panGesture的拖拽操作粹舵,否則劃動和拖拽操作會產(chǎn)生混淆

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];

[imageView addGestureRecognizer:panGesture];

[panGesture release];

*/

images = [[NSArray alloc] initWithObjects:@"iphone.png", @"mm.jpg", @"avatar.png", nil];

//默認情況下是向右的手勢劃動

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureHandler:)];

[imageView addGestureRecognizer:swipeGesture];

[swipeGesture release];

//定義向左的手勢劃動

UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureHandler:)];

swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;

[imageView addGestureRecognizer:swipeLeftGesture];

[swipeLeftGesture release];

//開始長按的內容部分

UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressGestureHandler:)];

longpressGesture.minimumPressDuration = 1;

longpressGesture.allowableMovement = 15;

longpressGesture.numberOfTouchesRequired = 1;

[imageView addGestureRecognizer:longpressGesture];

[longpressGesture release];

[super viewDidLoad];

}

- (IBAction)tapGestureHandler:(UIGestureRecognizer *)sender{

if (sender.view.contentMode == UIViewContentModeScaleAspectFit) {

sender.view.contentMode = UIViewContentModeScaleAspectFill;

} else {

sender.view.contentMode = UIViewContentModeScaleAspectFit;

}

}

- (IBAction)pinchGestureHandler:(UIGestureRecognizer *)sender{

CGFloat scaleValue = [(UIPinchGestureRecognizer *)sender scale];

if (scaleValue > 1) {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue + (scaleValue-1), lastScaleValue + (scaleValue-1));

}else {

sender.view.transform = CGAffineTransformMakeScale(lastScaleValue * scaleValue, lastScaleValue * scaleValue);

}

if (sender.state == UIGestureRecognizerStateEnded) {

if (scaleValue > 1) {

lastScaleValue += (scaleValue - 1);

}else {

lastScaleValue += scaleValue;

}

}

}

- (IBAction)rotationGestureHandler:(UIGestureRecognizer *)sender{

CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];

CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + rotationValue);

sender.view.transform = transform;

if (sender.state == UIGestureRecognizerStateEnded) {

rotationValue += rotation;

}

}

- (IBAction)panGestureHandler:(UIGestureRecognizer *)sender{

CGPoint position = [(UIPanGestureRecognizer *)sender translationInView:imageView];

sender.view.transform = CGAffineTransformMakeTranslation(position.x + position.x,

position.y + position.y);

if (sender.state == UIGestureRecognizerStateEnded) {

positionValue.x += position.x;

positionValue.y += position.y;

}

}

- (IBAction)swipeGestureHandler:(UIGestureRecognizer *)sender{

UISwipeGestureRecognizerDirection direction =[(UISwipeGestureRecognizer *)sender direction];

switch (direction) {

case UISwipeGestureRecognizerDirectionUp:

NSLog(@"向上劃動");

break;

case UISwipeGestureRecognizerDirectionDown:

NSLog(@"向下劃動");

break;

case UISwipeGestureRecognizerDirectionLeft:

imageIndex++;

break;

case UISwipeGestureRecognizerDirectionRight:

imageIndex--;

break;

default:

break;

}

imageIndex = (imageIndex < 0) ? ([images count] - 1):imageIndex % [images count];

imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];

}

- (IBAction)longpressGestureHandler:(UIGestureRecognizer *)sender{

if ([(UILongPressGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan) {

UIActionSheet *actionSheet = [[UIActionSheet alloc]

initWithTitle:@"圖片操作"

delegate:self

cancelButtonTitle:nil

destructiveButtonTitle:nil

otherButtonTitles:@"保存", @"復制", nil];

[actionSheet showInView:self.view];

[actionSheet release];

}

}

- (void)dealloc {

[images release];

[imageView release];

[super dealloc];

}

- (void)viewDidUnload {

[self setImageView:nil];

[super viewDidUnload];

}

@end

多點觸摸識別

有些時候,我們只想簡單地去識別用戶在屏幕上的操作骂倘,而不是只針對某個特定的view眼滤,我們可以通過以下四個方法進行屏幕的觸摸的識別。

touchesBegan:withEvent:當有一個或多個手指觸摸屏幕時被觸發(fā)稠茂。

touchesMoved:withEvent:當有一個或多個手指在屏幕上移動時被觸發(fā)柠偶。

touchesEnded:withEvent:當有一個或多個手指離開屏幕時被觸發(fā)。

touchesCancelled:withEvent: 當系統(tǒng)事件(內存溢出警告或者來電)發(fā)生時睬关,取消觸摸操作诱担。

檢測單點觸摸

HomeViewController.h code:

#import

@interface HomeViewController : UIViewController

@property (retain, nonatomic) IBOutlet UIImageView *imageView;

@end

HomeViewController.m code:

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

NSSet *allTouches = [event allTouches];

switch ([allTouches count]) {

case 1:

{

UITouch *touch = [[allTouches allObjects] objectAtIndex:0];

if ([touch tapCount] == 1 ) {

imageView.contentMode = UIViewContentModeScaleAspectFit;

}else if ([touch tapCount] == 2) {

imageView.contentMode = UIViewContentModeScaleAspectFill;

}

}

break;

default:

break;

}

}

- (void)viewDidLoad

{

[super viewDidLoad];

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

@end

檢測多點觸摸

HomeViewController.h code:

#import

@interface HomeViewController : UIViewController

@property (retain, nonatomic) IBOutlet UIImageView *imageView;

- (CGFloat)distance:(CGPoint)fromPoint toPoint:(CGPoint)toPoint;

@end

HomeViewController.m code:

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

@synthesize imageView;

CGFloat originalDistance;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

NSSet *allTouches = [event allTouches];

switch ([allTouches count]) {

case 1:{

UITouch *touch = [[allTouches allObjects] objectAtIndex:0];

if ([touch tapCount] == 1 ) {

imageView.contentMode = UIViewContentModeScaleAspectFit;

}else if ([touch tapCount] == 2) {

imageView.contentMode = UIViewContentModeScaleAspectFill;

}

}

break;

case 2:{

UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];

UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

CGPoint touch1PT = [touch1 locationInView:[self view]];

CGPoint touch2PT = [touch2 locationInView:[self view]];

NSLog(@"Touch1:%.0f, %.0f", touch1PT.x, touch1PT.y);

NSLog(@"Touch2:%.0f, %.0f", touch2PT.x, touch2PT.y);

originalDistance = [self distance:touch1PT toPoint:touch2PT];

}break;

default:

break;

}

}

- (CGFloat)distance:(CGPoint)fromPoint toPoint:(CGPoint)toPoint{

float lengthX = fromPoint.x - toPoint.x;

float lengthY = fromPoint.y - toPoint.y;

return sqrt((lengthX * lengthX) + (lengthY * lengthY));

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

NSSet *allTouches = [event allTouches];

switch ([allTouches count]) {

case 1:

break;

case 2:{

UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];

UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

CGPoint touch1PT = [touch1 locationInView:[self view]];

CGPoint touch2PT = [touch2 locationInView:[self view]];

NSLog(@"Touch1:%.0f, %.0f", touch1PT.x, touch1PT.y);

NSLog(@"Touch2:%.0f, %.0f", touch2PT.x, touch2PT.y);

CGFloat currentDistance = [self distance:touch1PT toPoint:touch2PT];

if (currentDistance > originalDistance) {

imageView.frame = CGRectMake(imageView.frame.origin.x-2,imageView.frame.origin.y-2,

imageView.frame.size.width+4, imageView.frame.size.height+4);

}else {

imageView.frame = CGRectMake(imageView.frame.origin.x+2, imageView.frame.origin.y+2,

imageView.frame.size.width-4, imageView.frame.size.height-4);

}

originalDistance = currentDistance;

}break;

default:

break;

}

}

- (void)viewDidLoad

{

[super viewDidLoad];

}

- (void)dealloc {

[imageView release];

[super dealloc];

}

@end

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市电爹,隨后出現(xiàn)的幾起案子蔫仙,更是在濱河造成了極大的恐慌,老刑警劉巖丐箩,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件摇邦,死亡現(xiàn)場離奇詭異恤煞,居然都是意外死亡,警方通過查閱死者的電腦和手機施籍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門居扒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人丑慎,你說我怎么就攤上這事喜喂。” “怎么了竿裂?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵玉吁,是天一觀的道長。 經(jīng)常有香客問我腻异,道長进副,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任悔常,我火速辦了婚禮影斑,結果婚禮上,老公的妹妹穿的比我還像新娘机打。我一直安慰自己鸥昏,他們只是感情好,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布姐帚。 她就那樣靜靜地躺著吏垮,像睡著了一般。 火紅的嫁衣襯著肌膚如雪罐旗。 梳的紋絲不亂的頭發(fā)上膳汪,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天,我揣著相機與錄音九秀,去河邊找鬼遗嗽。 笑死,一個胖子當著我的面吹牛鼓蜒,可吹牛的內容都是我干的痹换。 我是一名探鬼主播,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼都弹,長吁一口氣:“原來是場噩夢啊……” “哼娇豫!你這毒婦竟也來了?” 一聲冷哼從身側響起畅厢,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤冯痢,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體浦楣,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡袖肥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了振劳。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片椎组。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖历恐,靈堂內的尸體忽然破棺而出庐杨,到底是詐尸還是另有隱情,我是刑警寧澤夹供,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站仁堪,受9級特大地震影響哮洽,放射性物質發(fā)生泄漏。R本人自食惡果不足惜弦聂,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一鸟辅、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧莺葫,春花似錦匪凉、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至堡纬,卻和暖如春聂受,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背烤镐。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工蛋济, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人炮叶。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓碗旅,卻偏偏與公主長得像,于是被迫代替她去往敵國和親镜悉。 傳聞我的和親對象是個殘疾皇子祟辟,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內容