标题可能不是很清楚,但我想要做的是让UIImageView显示一系列图像(有点像gif),我通过将animationImages
设置为一组图像,然后调用[imageView startAnimating];
。这工作正常。我也有用CABasicAnimation来移动UIImageView的代码,而且这个动画代码也能正常工作。但是,当我尝试同时为UIImageView的图像制作动画并尝试移动UIImageView时,UIImageView的图像停止动画。有没有解决方法?如何同时动画UIImageView的图像和UIImageView本身?
这里是我的动画中的UIImageView的内容代码:
self.playerSprite = [[UIImageView alloc] initWithImage:[self.player.animationImages objectAtIndex:0]];
[self.playerSprite setFrame:CGRectMake(self.center.x, self.center.y, self.tileSet.constants.TILE_WIDTH, self.tileSet.constants.TILE_HEIGHT)];
self.playerSprite.animationImages = self.player.animationImages;
self.playerSprite.animationDuration = self.tileSet.constants.animationDuration;
self.playerSprite.animationRepeatCount = 0; //Makes it repeat indefinitely
下面是我用一个CABasicAnimation动画的UIImageView的编码:
float playerSpriteX = self.playerSprite.center.x;
float playerSpriteY = self.playerSprite.center.y;
CABasicAnimation *moveAnimation = [CABasicAnimation animation];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(playerSpriteX + TILE_WIDTH, playerSpriteY)];
[moveAnimation setDelegate:self];
[moveAnimation setFillMode:kCAFillModeForwards];
[moveAnimation setRemovedOnCompletion:NO];
[moveAnimation setDuration:MOVE_ANIMATION_DURATION];
[self.playerSprite.layer addAnimation:moveAnimation forKey:@"position"];
所以GIF效果不工作时UIImageView的位置正在动画化。我的问题是我该如何做到这一点,所以当UIImageView的位置被动画化时,UIImageView会循环显示一组图像。
添加了一些细节和说明视频到我的答案。 – matt