2012-02-03 5 views
0

5 개의 이미지를 스크롤해야하는 가로 스크롤보기가 있습니다. 첫 번째 이미지는 항상 공백 (검은 색 화면)이고 스크롤하면 이미지 1 - 4가 표시됩니다. 내 코드가 이미지 1에서 시작하지 않은 이유는 무엇입니까?UIScrollView Objective C의 빈 페이지로 시작

- (void)setupPage 
{ 
scrollView.delegate = self; 

[self.scrollView setBackgroundColor:[UIColor blackColor]]; 
[scrollView setCanCancelContentTouches:NO]; 

scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; 
scrollView.clipsToBounds = YES; 
scrollView.scrollEnabled = YES; 
scrollView.pagingEnabled = YES; 



NSUInteger nimages = 0; 
CGFloat cx = 0; 
for (; ; nimages++) { 
    NSString *imageName = [NSString stringWithFormat:@"day%d.jpg",  (nimages + 1)]; 
    UIImage *image = [UIImage imageNamed:imageName]; 
    if (image == nil) { 
     break; 
    } 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

    CGRect rect = imageView.frame; 
    rect.size.height = kScrollObjHeight; 
    rect.size.width = kScrollObjWidth; 
    rect.origin.x = scrollView.frame.size.width + cx; 
    rect.origin.y = ((scrollView.frame.size.height - image.size.height)/100); 

    imageView.frame = rect; 

    [scrollView addSubview:imageView]; 

    cx += scrollView.frame.size.width; 
} 

self.pageControl.numberOfPages = nimages; 
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)]; 

}

답변

1

라인

rect.origin.x = scrollView.frame.size.width + cx; 

그것을했다

rect.origin.x = cx; 
+0

을해야합니다. 감사! – Fitz