ios - UIScrollview 限制滑动区域

标签 ios xcode uiscrollview swipe

我想限制 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/

相关文章:

ios - Soundcloud sdk iOS 的正确 header 搜索路径是什么

ios - 从另一个 UIViewController 刷新表格

ios - 删除/编辑 ALAssetsLibrary 中的专辑组,可以吗?

ios - UITableViewCell 不显示

iPhone:在 viewWillAppear 之前的 viewDidLoad 之后会调用什么?

ios - UIScrollView 似乎在 xcode 6 (iOS 8) 中不起作用

ios - 如何在 UIScrollview 中嵌入 UITableView

ios - 将 Cloud Code 与 Parse Server 和 Heroku 结合使用

iphone - 在 View 之间显示图像

ios - 用实际代码替换Xcode中定义的代码