![](/img/trans.png)
[英]iPhone sdk Cocoa Touch - Pass touches down from parent UIView to child UIScrollview
[英]Parent UIScrollView detecting child UIView's touches
基本上...
我有一個UIScrollView子類,您也可以添加目標和選擇器,如果在視圖中檢測到觸摸事件,則會觸發該目標和選擇器。 我使用滾動視圖作為圖庫,並且滾動視圖內部的觸摸用於淡出HUD組件(UItoolBar等):
@implementation TouchableScrollView
- (void)addTarget:(id)_target withAction:(SEL)_action
{
target = _target;
action = _action;
shouldRun = NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
shouldRun = YES;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
shouldRun = NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(shouldRun)
{
shouldRun = NO;
[target performSelector:action];
}
}
@end
然后,我添加了另一個自定義UIView作為對此的子視圖,該視圖具有以下設置(我都玩過這兩個設置):
self.userInteractionEnabled = YES;
self.exclusiveTouch = YES;
並使用以下代碼觸發動畫:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
問題是,即使自定義UIView檢測到觸摸並做出響應(通過將自身翻轉過來),也會觸發UIScrollView選擇器,從而使所有內容淡出。
請幫忙,我完全被困住了嗎?
最好在自定義ScrollView類中使用它
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if (!self.dragging) { [self.nextResponder touchesEnded: touches withEvent:event]; }
[super touchesEnded: touches withEvent: event];
self.nextResponder
是scrollView的子視圖。 因此,除了拖動(滾動)之外的其他事件將由您的主viewController處理。 在主View控制器中繼承觸摸事件方法。 您可以在那里查看特定視圖或圖像視圖的觸摸事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.