2011-03-19 33 views
0

基于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; 
    } 
} 

回答

0

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