ユーザーがUIScrollViewの境界外にスクロールできるようにするにはどうすればよいですか?
3374 次
2 に答える
6
スーパービューのさまざまなUIViewメソッドからスクロールビューにタッチイベントを転送してみて、それが機能するかどうかを確認できます。例えば:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[scrollView touchesBegan:touches withEvent:event];
}
// etc
または、スーパービューでUIPanGestureRecognizerを使用して、パンイベントを取得するときにスクロールビューのオフセットを明示的に設定することもできます。例えば:
- (void)handlePan:(UIPanGestureRecognizer *)pan
{
scrollView.contentOffset = [pan translationInView:scrollView];
}
// Or something like that.
于 2011-08-04T16:23:26.900 に答える
6
ピックアップがその境界の外に触れるように、をサブクラス化しUIScrollView
、オーバーライドしてみてください。このようなもの:hitTest:withEvent:
UIScrollView
@interface MagicScrollView : UIScrollView
@end
@implementation MagicScrollView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// Intercept touches 100pt outside this view's bounds on all sides
if (CGRectContainsPoint(CGRectInset(self.bounds, -100, -100), point)) {
return self;
}
return nil;
}
@end
レイアウトによっては、 のスーパービューをオーバーライドpointInside:withEvent:
する必要がある場合もあります。UIScrollView
詳細については、次の質問を参照してください: UIView の境界を超える相互作用
于 2015-12-08T06:03:57.750 に答える