2012-02-03 12 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

関連する問題