如何以编程方式在UIScrollview中创建UIScrollview

问题描述 投票:0回答:3

请告诉我如何在滚动视图中设置scrollview,如嵌套进程。

以下代码部分工作。

int x=10;
int y=10;


for(int i=0; i<5; i++)
{
    UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 50, 50)];
    scrollview.showsVerticalScrollIndicator=YES;
    scrollview.scrollEnabled=YES;
    scrollview.userInteractionEnabled=YES;
    scrollview.backgroundColor = [UIColor greenColor];
    [self.view addSubview:scrollview];
    scrollview.contentSize = CGSizeMake(50,50);
    y=y+95;
}

现在,我只能看到3个滚动视图,其他隐藏。如何创建要查看的主滚动,以便不隐藏子滚动视图?

ios iphone ios6 uiscrollview ios7
3个回答
1
投票

您需要有一个初始scrollView,然后将这些scrollViews放入其中。

UIScrollView * mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
mainScrollView.contentSize = CGSizeMake(50, (y + 95) * 5);
// further configure
[self.view addSubview: mainScrollView];

然后改变

[self.view addSubview:scrollview];

[mainScrollView addSubview: scrollView];

1
投票
//I have created Two Scroll view programmatically this way
UIScrollView *scrollViewOuter = [[UIScrollView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 600.0f, 600.0f)];
scrollViewOuter.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
scrollViewOuter.contentSize = CGSizeMake(2000.0f, 2000.0f);

UIScrollView *scrollViewInner = [[UIScrollView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 200.0f, 200.0f)];
scrollViewInner.backgroundColor = [UIColor whiteColor];
scrollViewInner.contentSize = CGSizeMake(2000.0f, 2000.0f);

[scrollViewOuter addSubview:scrollViewInner];

[self.window addSubview:scrollViewOuter];

//You can change frame and use in your own way

0
投票

只需创建一个足够大的父滚动视图来容纳5个较小的滚动视图,然后更改此行:

[self.view addSubview:scrollview];

[parentScrollView addSubview:scrollview];
© www.soinside.com 2019 - 2024. All rights reserved.