문제

Okay, so I am making an app somewhat similar to flappy bird, but instead using a helicopter and a tap and hold mechanic instead of a tap, first of all when I press and hold I have the helicopter file a picture of the helicopter going up, and when I let go, I have the file a picture of it going down. To make it more look fluid I want to create an animation of just simply shifting the helicopter up/down about 10 degrees every .05ish seconds, how would I right a timer to be able to do this. This is the command that switches the image file:

Heli.image = [UIImage imageNamed:@"HeliUp.png"];

or

Heli.image = [UIImage imageNamed:@"Helidown.png"];

Basically I want this:

Heli.image = [UIImage imageNamed:@"HeliUp1.png"];
(wait .05 seconds)
Heli.image = [UIImage imageNamed:@"Heli2.png"];
(wait .05 seconds)
Heli.image = [UIImage imageNamed:@"HeliUp5.png"];

Something along the lines of that, however I know you need to use a timer with intervals and such..

SECOND of all, how would I make it so that I only can move the helicopter up and down when this animation isn't going on, so it doesn't look stupid.

Any help is appreciated, thanks.

도움이 되었습니까?

해결책

In this case, the animation is straight-forward enough that you can handle it all within the UIImageView:

Heli.image = normalImage;
Heli.animationImages = @[ normalImage, upImage, normalImage, downImage ];
Heli.animationDuration = 4 * .05;
Heli.animationRepeatCount = 0;

To stop the animation just set animationImages to nil, to restart the animation reset animationImages = @[ ... ]

When you assign an array of images to animationImages, the images will be cycled through at a rate determined by animationDuration. If you subsequently assign nil to animationImages, then the the image property will be used to determine what is displayed. So, by assigning either nil or the array @[ normalImage, upImage, normalImage, downImage ] you can turn animation on and off.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top