开发者

how do i display a random image after an animation?

开发者 https://www.devze.com 2023-03-18 06:05 出处:网络
so im trying to make a rock paper scissors app activated by either a button or the accelerometer by first doing a short animation which cycles through the three, then display a random image(1 of the 3

so im trying to make a rock paper scissors app activated by either a button or the accelerometer by first doing a short animation which cycles through the three, then display a random image (1 of the 3) at the end of the animation. The animation itself works perfectly fine, but after it finishes the random image does not show.

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


It looks like you're not initializing your UIImageView. Also, for the random image, I recommend this code: (it's more flexible)

    NSArray*images = rockpaperscissorsView.animationImages;

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

    UIImage*randomImage = [images objectAtIndex:randomIndex];

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

Don't forget to release image once you're done with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消