0

我努力尝试,但无法在启用分页的另一个水平滚动视图中添加垂直滚动视图。我尝试寻找解决方案,但没有任何帮助。请帮忙。谢谢。以下是我尝试过的代码:

for (int i = 0; i < kNumImages; i++) {

    NSString *imageName = [NSString stringWithFormat:@"dots.png"];
    UIImage *image = [UIImage imageNamed:imageName];

    UIScrollView *insetScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
    insetScrollView.scrollEnabled = NO;
    UIView *insetView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];


    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(320*i, 300, 300, 21)];
    textLabel.backgroundColor = [UIColor clearColor];
    textLabel.text = @"MyRandomText";
    UIImageView *imageButton = [[UIImageView alloc] initWithImage:image];
    imageButton.frame = CGRectMake(320*i, 0, 320, 260);

    [insetView addSubview:imageButton];
    [insetView addSubview:textLabel];
    [insetScrollView addSubview:insetView];
    [mainScrollView addSubview: insetScrollView];
    [mainScrollView setDelegate:self];
    [self.view addSubview:mainScrollView];
}
4

1 回答 1

0

为什么你们都是insetScrollView 设置frame origin x=0?

所以试试这个。

UIScrollView *insetScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(320*i, 0, 320, 300)];

 mainScrollView<->
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||   inset0      |   inset1        |    inset2     |   inset3      |   inset4   ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
于 2013-02-10T09:31:33.537 回答