UIScrollView
サイドでのヒット テストは必要ありません。遅延はUIScrollView
それ自体によって設定されるためです。カスタムのサブクラス化と実装は、hitTest:withEvent:
まだ遅延してトリガーされるため、役に立ちません。
iOSアプリケーションスイッチャーでアップル独自のボリュームスライダーをシミュレートしたかったので、これに対するエレガントなソリューションを何時間も探しました。
トリック:
yourScrollView.delaysContentTouches = NO;
残念ながら、これはUISliders
トラックに沿ったイベントを無効にするため、この部分でUIScrollView
は、最初にスライダーによってキャッチされるため、タッチイベントをトリガーしません。
サム四角形以外の touchevents を渡すにはUISliders
、サブクラスUISlider
化して以下を追加する必要があります。
// get the location of the thumb
- (CGRect)thumbRect
{
CGRect trackRect = [self trackRectForBounds:self.bounds];
CGRect thumbRect = [self thumbRectForBounds:self.bounds
trackRect:trackRect
value:self.value];
return thumbRect;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGRect thumbFrame = [self thumbRect];
// check if the point is within the thumb
if (CGRectContainsPoint(thumbFrame, point))
{
// if so trigger the method of the super class
NSLog(@"inside thumb");
return [super hitTest:point withEvent:event];
}
else
{
// if not just pass the event on to your superview
NSLog(@"outside thumb");
return [[self superview] hitTest:point withEvent:event];
}
}