无法将UIScrollView添加到另一个UIscrollView

时间:2013-02-10 07:24:33

标签: iphone uiscrollview

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

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];
}

1 个答案:

答案 0 :(得分:0)

为什么你们都是insetScrollView设置框架原点x = 0?

所以试试这个。

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

 mainScrollView<->
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||   inset0      |   inset1        |    inset2     |   inset3      |   inset4   ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||
||               |                 |               |               |            ||