UIScrollview限制滑动区域 [英] UIScrollview limit swipe area

查看:476
本文介绍了UIScrollview限制滑动区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试限制UIScrollview的滑动区域,但我无法做到这一点。

I am trying to limit the swipe area of the UIScrollview, but i amnot able to do that.

我想将滑动区域设置为顶部UIScrollview,但我想设置所有内容。

I would like to set the swipe area only to the top of the UIScrollview, but i would like to set all the content visible.

更新:

- (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

Solution: dont forget to set delaysContentTouches to NO on the UIScrollView

self.categoryScrollView.delaysContentTouches = NO;


推荐答案

您可以在 UIScrollView ,在视图控制器中覆盖 touchesBegan:withEvent:,检查是否有任何触摸开始于您要启用的区域滑动,如果答案为是,则重新启用滚动。同时覆盖 touchesEnded:withEvent: touchesCancelled:withEvent:以在触摸结束时禁用滚动。

You can disable scrolling on the UIScrollView, override touchesBegan:withEvent: in your view controller, check if any of the touches began in the area where you'd like to enable swipes, and if the answer is 'yes', re-enable scrolling. Also override touchesEnded:withEvent: and touchesCancelled:withEvent: to disable scrolling when the touches are over.

这篇关于UIScrollview限制滑动区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆