0

我是iOS的初学者。我创建了一个UIScrollview包含 5 个图像的图像,并根据方向设置其宽度、高度和大小变化。添加所有 5 张图像后,滚动视图子视图计数为 5。但是当开始拖动时计数增加到 7。我不知道在哪里添加了空白视图。


代码

-(void)addImageWithName:(NSString*)imageString atPosition:(int)position {

    UIImage *image = [UIImage imageWithContentsOfFile:imageString];
    imageView = [[UIImageView alloc] initWithImage:image];
    // imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    imageView.frame = CGRectMake(position*scrollview.frame.size.width*2, 0, scrollview.frame.size.width *2,scrollview.frame.size.height );
    imageView.tag = 1000 + position +1;

    [scrollview addSubview:imageView];
}

-(void)imageLoad:(NSInteger)startImage
{

    int Index = -1;
    for (UIImageView *subview in scrollview.subviews)
    {

        [subview removeFromSuperview];
    }


    for (int i = startImage; i < startImage+5; i++) {

        Index++;


        fullPath = [dataPath stringByAppendingString:[NSString stringWithFormat:@"/image%d.jpg",i]];


        [self addImageWithName:fullPath atPosition:Index];
        scrollview.contentSize = CGSizeMake(i*scrollview.frame.size.width, 0);

    }

}
4

1 回答 1

6

当您开始滚动时,滚动条视图会临时添加为子视图。

于 2012-12-28T13:12:04.077 回答