iOS各種手勢識別

2021-06-27 21:14:42 字數 2375 閱讀 5615

#import "viewcontroller.h"

@inte***ce viewcontroller ()

@property (nonatomic, strong) uiimageview *imageview;

@end

@implementation viewcontroller

@synthesize imageview = _imageview;

- (void)viewdidload

- (void)didreceivememorywarning

#pragma mark handle gestures methods

/* step5:去實現處理撲捉到手勢之後的動作 */

/* 識別單擊 */

- (void)handlesingletap:(uitapgesturerecognizer *)gesturerecognizer ];

}/* 識別雙擊 */

- (void)handledoubletap:(uitapgesturerecognizer *)gesturerecognizer ];

}/* 識別兩個手指擊 */

- (void)handletwofingertap:(uitapgesturerecognizer *)gesturerecognizer ];

}/* 識別側滑 */

- (void)handleswipe:(uiswipegesturerecognizer *)gesturerecognizer

else if (gesturerecognizer.direction == uiswipegesturerecognizerdirectionup)

else if (gesturerecognizer.direction == uiswipegesturerecognizerdirectiondown)

else

[uiview animatewithduration:0.5 animations:^];

}/* 識別翻轉 */

- (void)handlerotation:(uirotationgesturerecognizer *)gesturerecognizer ];

}}/* 識別拖動 */

- (void)handlepan:(uipangesturerecognizer *)gesturerecognizer

/* 識別放大縮小 */

- (void)handlepinch:(uipinchgesturerecognizer *)gesturerecognizer

/* 識別長按 */

- (void)handlelongpress:(uilongpressgesturerecognizer *)gesturerecognizer

#pragma mark -

#pragma mark drawing the image view

/* */

- (void)drawimageforgesturerecognizer:(uigesturerecognizer *)recognizer

atpoint:(cgpoint)centerpoint underadditionalsituation:(nsstring *)addtionalsituation

else if ([addtionalsituation isequaltostring:@"doubletap"])

else if ([addtionalsituation isequaltostring:@"twofingertap"])

else

}else if ([recognizer ismemberofclass:[uirotationgesturerecognizer class]])

else if ([recognizer ismemberofclass:[uiswipegesturerecognizer class]])

else if ([recognizer ismemberofclass:[uipinchgesturerecognizer class]])

else if ([recognizer ismemberofclass:[uipangesturerecognizer class]])

else if ([recognizer ismemberofclass:[uilongpressgesturerecognizer class]])

else

self.imageview.image = [uiimage imagenamed:imagename];

self.imageview.center = centerpoint;

self.imageview.alpha = 1.0;

}@end

iOS 手勢識別

首先給大家解釋一下為什麼要學習手勢識別?如果想監聽乙個uiview上面的觸控事件,之前的做法是 自定義乙個uiview 實現uiview的touches方法,在方法裡面實現具體功能 透過touches監聽uiview的觸控事件,有很明顯的幾個缺點 1.必須要自定義uiview,2.由於是在view內...

iOS手勢識別初探

uigesturerecognizerstate的定義如下 typedef ns enum nsinteger,uigesturerecognizerstate uigesturerecognizerstatepossible 預設狀態,手勢識別器尚未識別出手勢,但是可能已經在處理觸屏事件了。uig...

iOS 手勢識別器概述

其相應的方法 initwithtarget action addtarget action removetarget action locationinview locationoftouch inview numberoftouches屬性 requiregesturerecognizertofa...