Vis*_*áté 9 xcode uiscrollview swipe ios
我试图限制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];
}
Run Code Online (Sandbox Code Playgroud)
解决方案:别忘了在UIScrollView上将delaysContentTouches设置为NO
self.categoryScrollView.delaysContentTouches = NO;
Run Code Online (Sandbox Code Playgroud)
您可以在视图控制器中禁用滚动UIScrollView,覆盖touchesBegan:withEvent:,检查是否在您要启用滑动的区域中开始任何触摸,如果答案为"是",则重新启用滚动.同时覆盖touchesEnded:withEvent:并touchesCancelled:withEvent:在触摸结束时禁用滚动.
其他答案对我不起作用.子类UIScrollView为我工作(Swift 3):
class ScrollViewWithLimitedPan : UIScrollView {
// MARK: - UIPanGestureRecognizer Delegate Method Override -
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
let locationInView = gestureRecognizer.location(in: self)
print("where are we \(locationInView.y)")
return locationInView.y > 400
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3655 次 |
| 最近记录: |