基于UIScrollView的图像库在图像顶部获得白色间隙

时间:2011-03-19 17:37:31

标签: ios4 uiscrollview

基于UIScrollView的图库在图像顶部出现白色间隙,图像被向下推了一下。如何删除空白区域?

@implementation PagerViewController

- (void) setImages:(NSArray *) images
{
    if(imageSet) [imageSet release];

    imageSet = [images retain];

    view1.frame = CGRectMake(0,0,320,480);
    view2.frame = CGRectMake(320,0,320,480);

    view1.image = [imageSet objectAtIndex:0];
    view2.image = [imageSet objectAtIndex:1];

    scroll.contentSize = CGSizeMake([imageSet count]*320,480);
}

- (id) init
{
    if(self = [super init])
    {
        scroll = [[UIScrollView alloc] init];
        scroll.scrollEnabled = YES;
        scroll.pagingEnabled = YES;
        scroll.directionalLockEnabled = YES;
        scroll.showsVerticalScrollIndicator = NO;
        scroll.showsHorizontalScrollIndicator = NO;
        scroll.delegate = self;
        scroll.backgroundColor = [UIColor clearColor];
        scroll.autoresizesSubviews = YES;
        scroll.frame = CGRectMake(0,0,320,480);
        [self.view addSubview:scroll];

        view1 = [[UIImageView alloc] init];
        [scroll addSubview:view1];

        view2 = [[UIImageView alloc] init];
        [scroll addSubview:view2];
    }

    return self;
}

- (void) update
{
    CGFloat pageWidth =320;
    float currPos = scroll.contentOffset.x;

    int selectedPage = roundf(currPos / pageWidth);

    float truePosition = selectedPage*pageWidth;

    int zone = selectedPage % 2;

    BOOL view1Active = zone == 0;

    UIImageView *nextView = view1Active ? view2 : view1;

    int nextpage = truePosition > currPos ? selectedPage-1 : selectedPage+1;

    if(nextpage >= 0 && nextpage < [imageSet count])
    {
        if((view1Active && nextpage == view1Index) || (!view1Active && nextpage == view2Index)) return;

        NSLog(@"Load next image!");

        nextView.frame = CGRectMake(nextpage*320,0,320,480);
        nextView.image = [imageSet objectAtIndex:nextpage];

        if(view1Active) view1Index = nextpage;
        else view2Index = nextpage;
    }
}

1 个答案:

答案 0 :(得分:0)

在.plist文件中编辑“状态栏最初隐藏 - 已检查”解决了它!