當我在UIScrollView中頻繁滾動圖像,然後在一些圖像之後,下一個圖像需要時間來加載......它沒有花費太多時間,但看起來很奇怪。大圖像的ScrollView滾動速度太慢
假設我在一個scrollView中有27個圖像。當我開始滾動這些圖像時,對於1或2張圖像可以平滑滾動,但當再次滾動以查看第3張圖像時,需要時間加載。然後,當我從第三張圖像開始再次滾動圖像時,它的行爲就像以前一樣。
我一次無法加載全部27張圖片或者我的應用程序崩潰。
當我緩慢滾動scrollview然後我沒有這個問題。
我的代碼如下:
//Taking image view for 27 images;
int x=0;
for(int i = 1; i<=27; i++) {
imageView = [[UIImageView alloc] init];
imageView .frame = CGRectMake(x,0,768,1024);
imageView.tag=i;
imageView.image=nil;
imageView.userInteractionEnabled=YES;
[contentView addSubview:imageView];
x+=768;
}
//setContentOffset of the scrollView -->ContentView
[contentView setContentOffset: CGPointMake((imageNumber-1)*768, 0) animated: YES];
//desire image which i want to see from the start of the scrollview
pageNumber=imageNumber;
int pageBefore=pageNumber-1;
int pageAfter=pageNumber+1;
//Views for image
for(UIImageView * views in [contentView subviews]){
if(views.tag==pageNumber){
if(views.image==nil){
NSLog(@"entering");
views.image=[UIImage imageNamed:[ NSString stringWithFormat:@"%d.jpg",pageNumber]];
[views.image release];
}
}
if(views.tag==pageBefore){
if(views.image==nil){
views.image=[UIImage imageNamed:[ NSString stringWithFormat:@"%d.jpg",pageBefore]];
[views.image release];
}
}
if(views.tag==pageAfter){
if(views.image==nil){
views.image=[UIImage imageNamed:[ NSString stringWithFormat:@"%d.jpg",pageAfter]];
[views.image release];
}
}
感謝Roger爲您的迴應。在您的鬧鐘響起的角度,我會說,我已經說我在iphone應用程序開發新。現在,如果簡單地解釋一下,這對我會有幫助。可能我正在花時間,但你知道分享和關心。提前致謝。 – 2011-04-19 04:40:46
值得在這裏閱讀,因爲它有一些代碼示例,並更多地解釋了這個問題。 http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/ – Roger 2011-04-19 08:45:48