UIScrollView攔截所有觸摸事件,因爲它必須決定用戶是否/何時移動手指以滾動滾動視圖。 你可能想繼承的UIView,然後在
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;
方法,請檢查neccessary觸摸,然後轉發所有的這些方法您UIScrollViewInstance。例如:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface MyView: UIView {
UIScrollView *scrollView;
}
@end
@implementation MyView
/* don't forget to alloc init your ScrollView init -init
and release it in -dealloc! Then add it as a subview of self. */
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt
{
/* check for a gesture */
[scrollView touchesBegan:touches withEvent:evt];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
{
/* check for a gesture */
[scrollView touchesMoved:touches withEvent:evt];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;
{
/* check for a gesture */
[scrollView touchesEnded:touches withEvent:evt];
}
@end
我一定會檢查這個解決方案,但同時我試圖繼承ScrollView並覆蓋hitTest並檢查tapCount。如果它1,則返回超級視圖,否則自己。 但是,你能告訴我tapCount爲什麼是零? – 2012-01-30 13:00:04