2011-07-07 37 views
0

所以我試圖製作一個通過按鈕或加速計激活的岩石紙剪刀應用程序,首先做一個循環通過三個短的動畫,然後在動畫結束時顯示一個隨機圖像(3的1)。動畫本身工作得很好,但完成後,隨機圖像不顯示。如何在動畫之後顯示隨機圖像?

UIImageView *image; 
int x = arc4random() % 3 + 1; 
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", x]; 
UIImage *img = [UIImage imageNamed:imageName]; 

回答

2

它看起來像你沒有初始化你的UIImageView。另外,隨機的形象,我建議這樣的代碼:(它更靈活)

NSArray*images = rockpaperscissorsView.animationImages; 

    NSUInteger randomIndex = arc4random() % [images count]; 

    UIImage*randomImage = [images objectAtIndex:randomIndex]; 

    UIImageView*image = [[UIImageView alloc] initWithImage:randomImage]; 

不要忘記釋放image一旦你用它做。

+0

謝謝一堆:) – fornon

+0

沒問題!如果這是您正在查找的答案,請通過單擊綠色複選標記圖標將其標記爲已接受。歡迎來到社區! – Pripyat