我有一個分段控件,允許短手勢和長手勢。短手勢識別很好。長手勢方法被調用兩次。我爲什麼撓撓頭。Xcode/ios5 - 長觸手勢兩次
這是代碼來構建一個顏色工具欄的一部分:
UILongPressGestureRecognizer* longPressGestureRec =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
longPressGestureRec.minimumPressDuration = 1.5;
//longPressGestureRec.cancelsTouchesInView = NO;
[colorControl addGestureRecognizer:longPressGestureRec];
這是長按方法的一部分:
-(void) longPress:(id)sender {
NSLog(@"%s", __FUNCTION__);
switch (colorIndex) {
case 0:
[self showMoreWhiteColors:(id)sender];
break;
case 1:
[self showMoreRedColors:(id)sender];
break;
通過查看日誌,我可以看到,長按每次按住按鈕時都會調用兩次方法。
任何想法我做錯了什麼,錯過,沒有做....?
在這裏找到答案: http://stackoverflow.com/questions/3319591/uilongpressgesturerecognizer-gets-called-twice-when-pressing-down – Philip 2012-04-26 23:48:24
嗨菲利普。感謝您的迴應。我看到那個帖子。那裏似乎有幾個相互矛盾的答案。你會建議什麼? – 2012-04-27 01:27:52