標題可能不是很清楚,但我想要做的是讓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