0
我創建了一個UIGestureRecognizer
子類,稱爲LongPressGestureRecognizer
模擬長按手勢。 (是的,我知道已經存在,我只是學習Objective-C和試驗了一下具體子類)。自定義手勢不發送動作消息
我也只覆蓋了以下方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.state = UIGestureRecognizerStatePossible;
[self performSelector:@selector(setState:) withObject:[NSNumber numberWithInt:UIGestureRecognizerStateRecognized] afterDelay:2];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
self.state = UIGestureRecognizerStateCancelled;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
self.state = UIGestureRecognizerStateFailed;
}
在我看來,控制器屬性recognizer
存儲手勢識別器,我有以下代碼:
- (LongPressGestureRecognizer *)recognizer
{
if (!_recognizer) {
_recognizer = [[LongPressGestureRecognizer alloc] init];
}
return _recognizer;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.recognizer addTarget:self action:@selector(log:)];
[self.view addGestureRecognizer:self.recognizer];
}
- (IBAction)log:(LongPressGestureRecognizer *)recognizer
{
//blah blah blah
}
我的問題是log:
是沒有得到所謂的在所有...通過在控制檯登錄的UIGestureRecogniserState
S,我知道手勢識別器正在工作,只要狀態而言預計...
我在做什麼錯在這裏?
感謝的人......工作完美:) – Roshan