2012-01-30 82 views
3

我有一個UIView包含UIScrollView。 這個UIView應該會響應一些觸摸事件,但由於它包含的scrollView而沒有響應。如何從其父視圖中停止UIScrollView獲取觸摸事件?

此scrollView的contentView設置爲OuterView內的MoviePlayer。 現在每當我點擊MoviePlayer所在的區域時,我的OuterView的觸摸事件都沒有響應。

我甚至將電影播放器​​的userInteraction設置爲NO

但現在scrollView干擾它似乎。

我已經提到SO本身的這篇文章。

How can a superview interecept a touch sequence before any of its subviews?

但也有解決方案,問我設置userInteractionEnabledNO爲滾動視圖 但如果我這樣做,我的雙指縮放不會發生任何!

怎麼辦?

回答

0

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 
+0

我一定會檢查這個解決方案,但同時我試圖繼承ScrollView並覆蓋hitTest並檢查tapCount。如果它1,則返回超級視圖,否則自己。 但是,你能告訴我tapCount爲什麼是零? – 2012-01-30 13:00:04

相關問題