簡體   English   中英

UIGestureRecognizer-永遠不會調用重置

[英]UIGestureRecognizer - reset is never called

我正在創建自定義手勢識別器。 問題在於,永遠不會調用reset方法,因此我無法重置識別器的狀態。 因此,它只能在第一次使用

@implementation TouchGestureRecognizer {

    UIGestureRecognizerState mState;
}

-(UIGestureRecognizerState) state {
    return mState;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if( [touches count] == 1 ) {
        mState = UIGestureRecognizerStateBegan;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if( [touches count] == 1 ) {
        mState = UIGestureRecognizerStateChanged;
    }
}

- (void)reset {
    mState = UIGestureRecognizerStatePossible;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    mState = UIGestureRecognizerStateRecognized;
}

@end

該文檔指出:

將手勢識別器狀態設置為UIGestureRecognizerStateEnded或UIGestureRecognizerStateRecognized后,運行時將調用此方法。

看來這就是您在touchesEnded:中所做的。 在此方法中放置一個斷點,然后從那里獲取它。

您必須將其寫入.h文件中。

#import <UIKit/UIGestureRecognizerSubclass.h>

暫無
暫無

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

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