我發佈此消息是因爲我一直在閱讀論壇,並且我一直無法找到類似的問題。我需要能夠區分水龍頭和雙擊(這是一個標準的事情),但我的問題是,無論出於什麼原因,我有一個滾動視圖在另一個滾動視圖。所以,我不得不對我的ScrollView進行子類化,以便獲得一個名爲「touchBegin」的方法。在ScrollView中捕獲單/雙擊的問題
我有一個名爲PhotoViewController(BaseViewController的子類)的類,該類包含另一個名爲CustomScrollView(ScrollView的子類)的類。我需要從ScrollView中對這個CustomScrollView進行子類化,以覆蓋touchesBegin方法,並且能夠捕獲用戶所做的觸摸。
我試着從TouchScrollView中使用類似touchesBegin方法的return [super touchesBegan:touches withEvent:event]來調用touchesBegin方法,但是當PhotoViewController裏的touchesBegin方法被調用時它的參數是空的(我不能區分如果用戶做出的單擊或雙擊,這正是我需要的)
我有一個類,叫做PhotoViewController:
@class PhotoViewController
@interface PhotoViewController : BaseViewController <UIScrollViewDelegate> {
CustomScrollView* myScrollView;
}
@implementation PhotoViewController
...
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
NSUInteger tapCount = [touch tapCount];
switch (tapCount) {
case 1:
[self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4];
break;
case 2:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil];
[self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4];
break;
default:
break;
}
}
類CustomScrollView是(CustomScrollView.h):
@interface CustomScrollViewPhoto : UIScrollView {
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
@end
,它的實施過程是這樣(CustomScrollView.m):
@implementation CustomScrollViewPhoto
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.superview touchesBegan:[NSSet set] withEvent:event];
return [super touchesBegan:touches withEvent:event];
}
我在錯誤的方向與我想做的事情了?也許,我應該捕獲CustomScrollView類內的水龍頭/雙擊(這工作正常!),並從那裏使用@選擇器或其他東西在PhotoViewController調用適當的方法?
感謝您的閱讀!
嗨,隊友,那肯定解決了它! TXS! – nachoman