在UIScrollview中拖动会增加其子视图计数

时间:2012-12-28 13:07:59

标签: iphone objective-c ios ios6

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


CODE

-(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);

    }

}

1 个答案:

答案 0 :(得分:6)

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