我想知道如何让用户滚动到UIScrollView的边界之外?
答案 0 :(得分:6)
您可以尝试将超级视图的各种UIView方法中的触摸事件转发到scrollview,看看是否可行。 E.g:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[scrollView touchesBegan:touches withEvent:event];
}
// etc
或者您可以尝试在superview上使用UIPanGestureRecognizer,并在获取pan事件时显式设置滚动视图偏移。 E.g:
- (void)handlePan:(UIPanGestureRecognizer *)pan
{
scrollView.contentOffset = [pan translationInView:scrollView];
}
// Or something like that.
答案 1 :(得分:4)
尝试对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
,具体取决于您的布局。
有关详细信息,请参阅以下问题:interaction beyond bounds of uiview