我想限制 UIScrollview 的滑动区域,但我做不到。
我只想将滑动区域设置到 UIScrollview 的顶部,但我想将所有内容设置为可见。
更新:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] > 0) {
UITouch *tempTouch = [touches anyObject];
CGPoint touchLocation = [tempTouch locationInView:self.categoryScrollView];
if (touchLocation.y > 280.0)
{
NSLog(@"enabled");
self.categoryScrollView.scrollEnabled = YES;
}
}
[self.categoryScrollView touchesBegan:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// [super touchesEnded:touches withEvent:event];
self.categoryScrollView.scrollEnabled = YES;
[self.categoryScrollView touchesBegan:touches withEvent:event];
}
解决方法: 不要忘记在 UIScrollView 上将 delaysContentTouches 设置为 NO
self.categoryScrollView.delaysContentTouches = NO;
最佳答案
您可以在 UIScrollView
上禁用滚动,覆盖 View Controller 中的 touchesBegan:withEvent:
,检查是否有任何触摸开始于您想要的区域启用滑动,如果答案为"is",则重新启用滚动。同时覆盖 touchesEnded:withEvent:
和 touchesCancelled:withEvent:
以在触摸结束时禁用滚动。
关于ios - UIScrollview 限制滑动区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8379555/