我試圖通過點擊一個按鈕時單個UIImageView
中的一些圖像循環。按下按鈕後,圖像必須消失0.1秒。 下面的代碼:延遲加載UIImageView中的圖像
int tapCount = 0;
UIImage *image0 = [UIImage imageNamed:@"0.jpg"];
UIImage *image1 = [UIImage imageNamed:@"1.jpg"];
UIImage *image2 = [UIImage imageNamed:@"2.jpg"];
imagesArray = [[NSArray alloc] initWithObjects:image0, image1, image2, nil];
-(IBAction)backgroundButton:(id)sender{
self.myImageView.image = [imagesArray objectAtIndex:tapCount%3];
tapCount++;
[self performSelector:@selector(eraseImage) withObject:self afterDelay:0.1];
}
-(void)eraseImage{
self.myImageView.image = nil;
}
的問題是,圖像不會出現,直到我已經完成了一個完整的環(在第4 TAP)。 我猜想,我必須初始化UIImageView
中的圖像,因爲它需要一定的時間纔會出現在敲擊和圖像之間,並且因爲它在0.1秒後消失......它根本不會顯示。
我試圖加載它們裏面viewDidLoad
這樣的:
for(int i = 0; i<[imagesArray count]; i++){
self.myImageView.image = [imagesArray objectAtIndex : i];
}
只是到最後的形象工程加載(在這種情況下,圖像2)。
我是否應該在不同的UIImageView
之間循環,而不是在單個UIImageView
內循環使用不同的UIImage
?
任何其他提示?
什麼是圖像,它們有多大?創建一個'UIImage'實際上並不會加載圖像數據(您需要將其渲染到上下文中才能發生)。 – Wain
圖像爲1MB到3MB之間的jpg。 1024x768,因爲必須在iPad中全屏顯示。 我怎樣才能加載它們? – guardabrazo
idk如果這是你如何擁有你的代碼,但我不應該在它的前面;它應該是[imagesArray objectAtIndex:i]; – user2277872