开发者

uiscrollview not scrolling horizontally

开发者 https://www.devze.com 2022-12-28 15:07 出处:网络
My UIScrollView below is not scrolling horizontally, Please help me here.. FirstView = [[UIView alloc] initWithFrame:CGRectMake(60, 0, 100, 150)];

My UIScrollView below is not scrolling horizontally, Please help me here..

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 all开发者_运维百科oc]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];

The HolderView is not scrolling horizontally but which happen, please help

Note: I have a mainView which adds this HolderView in its top section as per the frame coordinates.

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

This is complete structure


A scroll view will only scroll when its content size is bigger than its frame.


    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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号