我有一个带有滚动视图中显示的图像的数组。它在模拟器上完美运行,但是当我在实际设备(第一代 iPad)上运行它时,它崩溃了。起初我将图像质量降低到最低(每个<120kb),但这并没有解决我的问题。然后我将图像数量从 13 减少到 6 并且它起作用了。有没有你能想到的工作?以下是我使用的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
images = [NSArray arrayWithObjects:[UIImage imageNamed:@"back1.jpg"], [UIImage imageNamed:@"back2.jpg"], [UIImage imageNamed:@"back3.jpg"], [UIImage imageNamed:@"back4.jpg"], [UIImage imageNamed:@"back5.jpg"], [UIImage imageNamed:@"back6.jpg"], [UIImage imageNamed:@"back7.jpg"], [UIImage imageNamed:@"back8.jpg"],[UIImage imageNamed:@"back9.jpg"],[UIImage imageNamed:@"back10.jpg"],[UIImage imageNamed:@"back11.jpg"],[UIImage imageNamed:@"back12.jpg"],[UIImage imageNamed:@"back13.jpg"], nil];
pageControl.numberOfPages=images.count;
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
subview = [[UIImageView alloc] initWithFrame:frame];
subview.contentMode = UIViewContentModeScaleAspectFit;
subview.image = [images objectAtIndex:i]; //problima sthn eikona
[self.scrollView addSubview:subview];
}
pageControlBeingUsed = NO;
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height);}