UIScrollView仅向下滚动

时间:2011-08-03 16:31:26

标签: iphone objective-c ios uiscrollview uikit

我正在使用嵌套的UIScrollView实现自定义UIView。

初始化看起来像:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10, 252, 200)];        
        scrollView.backgroundColor = [UIColor clearColor];
        scrollView.contentSize = CGSizeMake(500, 400); 
        scrollView.userInteractionEnabled = YES;
        scrollView.pagingEnabled = NO;
        scrollView.scrollEnabled = YES;
        scrollView.clipsToBounds = YES;
        [scrollView setAutoresizesSubviews:YES];
        [scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
        [scrollView setDirectionalLockEnabled:NO];
        [scrollView setDelegate:self];

        [scrollView setShowsHorizontalScrollIndicator:YES];
        [scrollView setShowsVerticalScrollIndicator:YES];
        [scrollView setBounces:YES];
        [scrollView setAlwaysBounceHorizontal:NO];
        [scrollView setAlwaysBounceVertical:NO];
        [scrollView setBouncesZoom:YES];
        [scrollView setDelaysContentTouches:YES];
        [scrollView setCanCancelContentTouches:YES];

        [scrollView setMaximumZoomScale:1];
        [scrollView setMinimumZoomScale:1];
        [scrollView setOpaque:YES];

        [self addSubview:scrollView];                            
    }
    return self;
}
控制器中的

CustomView *customView = [[CustomView alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
[self.view addSubview:cut];

问题:滚动视图仅向上滚动(当我向下拖动手指时),当我尝试向左,向右或向下滚动时没有动作

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您设置的许多属性与默认值相同。您可以在此处找到默认值:UIScrollView Class Reference

我的建议是删除已经有默认值的属性。特别是滚动的属性。

[scrollView setShowsHorizontalScrollIndicator:YES];
[scrollView setShowsVerticalScrollIndicator:YES];
[scrollView setBounces:YES];
[scrollView setAlwaysBounceHorizontal:NO];
[scrollView setAlwaysBounceVertical:NO];
[scrollView setBouncesZoom:YES];
[scrollView setDelaysContentTouches:YES];
[scrollView setCanCancelContentTouches:YES];