我正在处理一个分页的 UIScrollView,但它只想在其中显示第一个 UIImageView。我将每个 UIImageView 添加到滚动视图宽度的偏移处,这样应该会创建每个页面。运行时,它说滚动视图是正确的页数,但图像不显示。
任何帮助将非常感激!
int numSlides = NUM_TUTORIAL_SLIDES;
NSString *fileName;
UIImageView *slideImageView;
CGRect slideFrame;
for (int i = 1; i <= numSlides; i++)
{
slideFrame.origin.x = self.tutorialScrollView.frame.size.width * (i-1);
slideFrame.origin.y = 0;
slideFrame.size = self.tutorialScrollView.frame.size;
slideImageView = [[UIImageView alloc] initWithFrame:slideFrame];
if([[AppManager sharedManager] is4inchScreen])
{
fileName = [NSString stringWithFormat:@"Slide%d4in@2x.png", i];
}
else
{
fileName = [NSString stringWithFormat:@"Slide%d@2x.png", i];
}
slideImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
[self.tutorialScrollView addSubview:slideImageView];
[slideImageView release];
}
self.tutorialScrollView.contentSize = CGSizeMake(self.tutorialScrollView.frame.size.width * numSlides, self.tutorialScrollView.frame.size.height);
self.tutorialScrollView.delegate = self;