【发布时间】:2013-04-15 22:31:59
【问题描述】:
标题可能不太清楚,但我想做的是让 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 在其位置被动画化的同时循环遍历一组图像?
【问题讨论】:
-
在我的回答中添加了一些细节和说明性视频。
标签: ios objective-c animation uiimageview cabasicanimation