标题可能不太清楚,但我想做的是让 UIImageView 显示一系列图像(有点像 gif),我通过将 设置animationImages
为图像数组然后调用[imageView startAnimating];
. 这工作正常。我还有用 CABasicAnimation 移动 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"];
因此,当 UIImageView 的位置被动画化时,gif 效果不起作用。我的问题是如何做到这一点,以便 UIImageView 在其位置被动画化时循环遍历一组图像?