簡體   English   中英

適用於所有類型的ios手勢識別器

[英]ios gesture recognizer for all types

我只需要知道是否有辦法在一個UIGestureRecognizer實例中捕獲所有類型的手勢。

示例:我有一個UIView,我必須檢測它上面的任何類型的點擊,而不為每種類型的手勢創建一個實例

有沒有辦法做到這一點 ?

謝謝,

當然,它是自己處理低級UIView事件( iOS事件處理指南 ):

Responding to Touch Events
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
Responding to Motion Events
– motionBegan:withEvent:
– motionEnded:withEvent:
– motionCancelled:withEvent:

您可以UIGestureRecognizer類,並在觸摸開始時將其內部狀態更改為UIGestureRecognizerStateRecognized

示例代碼:

@interface UITouchGestureRecognizer : UIGestureRecognizer

@end


#import <UIKit/UIGestureRecognizerSubclass.h>

@implementation UITouchGestureRecognizer

- (void) reset
{
    [super reset];
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    self.state = UIGestureRecognizerStateRecognized;
}

@end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM