[英]Passing touches through a UIView to a UIScrollView not working
我有一個從UIScrollView控制器派生的視圖,我用它來瀏覽庫中的圖像。 這很好。
我在右側覆蓋了一個UIView來處理觸摸,以便快速滾動圖像列表。 我的問題是,如果我將觸摸傳遞給'super'或'nextResponder',它們永遠不會進入下面的UIScrollView對象。
我的問題是如何強制下面的UIScrollView來處理我不需要處理的觸摸? 我正在設置一個0.3秒的計時器,在此期間所有觸摸都傳遞給UIScrollView進行處理。 因此,如果用戶啟動了滑動手勢來翻頁,則會發生這種情況。
這是touchesBegan方法的代碼:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
// Start a timer to trigger the display of the slider and the processing of events.
touchesTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(showSlider:) userInfo:nil repeats:NO];
// Where are we at right now?
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
lastPage = [self page:currentPoint.y];
// Pass the event though until we need it.
// [self.nextResponder touchesBegan:touches withEvent:event];
if ([touch.view isKindOfClass:[UIScrollView class]])
{
if (self.nextResponder != nil &&
[self.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)])
{
[self.nextResponder touchesEnded:touches withEvent:event];
}
}
}
我會嘗試使用常規的UIViewController而不是UIScrollViewController,然后在需要的地方添加滾動視圖對象,並在右側放置您想要的滾動視圖。 這種方式它們是分開的,觸摸不會混淆。
這是一個更適合我的簡單解決方案:
在UIScrollview頂部的UIView中,寬度和高度均為0(因此視圖不再在技術上位於UIScrollView之上)並設置clipsToBounds = NO(以便視圖的內容仍顯示在頂部UIScrollView中)。
self.OverlayView.clipsToBounds = NO;
CGRect frame = self.OverlayView.frame;
self.OverlayView.frame = CGRectMake(frame.origin.x, frame.origin.y, 0, 0);
請注意,如果UIView包含交互式控件,則它們將不再起作用。 您需要將其移動到UIScrollView上方的自己的視圖中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.