uiscrollview不能水平滚动

时间:2010-05-01 00:06:07

标签: iphone uiscrollview

下面我的UIScrollView没有横向滚动,请在这里帮助我..

FirstView = [[UIView alloc] initWithFrame:CGRectMake(60, 0, 100, 150)];
    [FirstView setBackgroundColor:[UIColor clearColor]];

    SecondView = [[UIView alloc] initWithFrame:CGRectMake(320+60, 0, 100, 150)];
    [SecondView setBackgroundColor:[UIColor clearColor]];

    HolderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1000, 150)];

    scrHorizontalScroll = [[UIScrollView alloc]initWithFrame:HolderView.frame];
        [scrHorizontalScroll setBackgroundColor:[UIColor redColor]];
    [scrHorizontalScroll setContentSize:CGSizeMake(999, 150)];
    [scrHorizontalScroll setScrollEnabled:YES];
    [HolderView addSubview:scrHorizontalScroll];
[scrHorizontalScroll addSubView:FirstView]; [scrHorizontalScroll addSubView:SecondView]; [HolderView addSubView: scrHorizontalScroll];

HolderView不是横向滚动但发生了,请帮助

注意:我有一个mainView,它根据帧坐标在其顶部添加此HolderView。

[mainView addSubView:label].... [mainView addSubView:HolderView];

这是完整的结构

2 个答案:

答案 0 :(得分:15)

滚动视图只会在其内容大小大于时滚动。

答案 1 :(得分:1)

    FirstView = [[UIView alloc] initWithFrame:CGRectMake(60, 0, 100, 150)];
        [FirstView setBackgroundColor:[UIColor clearColor]];

        SecondView = [[UIView alloc] initWithFrame:CGRectMake(320+60, 0, 100, 150)];
        [SecondView setBackgroundColor:[UIColor clearColor]];

        HolderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 150)];

        scrHorizontalScroll = [[UIScrollView alloc]initWithFrame:HolderView.frame];
            [scrHorizontalScroll setBackgroundColor:[UIColor redColor]];
        [scrHorizontalScroll setContentSize:CGSizeMake(999, 150)];
        [scrHorizontalScroll setScrollEnabled:YES];
        [HolderView addSubview:scrHorizontalScroll];
    [scrHorizontalScroll addSubView:FirstView]; [scrHorizontalScroll addSubView:SecondView]; [HolderView addSubView: scrHorizontalScroll];

//set with of the scrHorizontalScroll  as second view,increase content view size to x axis.