我想知道如何允许用户滚动到 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
超级视图,具体取决于您的布局。
有关更多信息,请参阅以下问题:interaction beyond bounds of uiview
于 2015-12-08T06:03:57.750 回答