我的代码可以很好地运行动画。问题是我希望整个动画移到屏幕的左侧,然后停止并重新开始。基本上它是一只动画熊,但我需要整个动画在屏幕上向左移动。我不希望它具有不同的动画效果,我只需要更改它的x值即可,但我遇到了麻烦。有人可以帮忙吗?到目前为止,这就是我所拥有的。
(无效)viewDidLoad
{
[super viewDidLoad];
NSArray *imageNames = @[@"bear1.gif", @"bear2.gif", @"bear3.gif", @"bear4.gif",
@"bear5.gif", @"bear6.gif"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++)
{
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
// Normal Animation
UIImageView * animationImageView = [[UIImageView分配] initWithFrame:CGRectMake(60,95,50,50)];
animationImageView.animationImages =图片;
animationImageView.animationDuration = 0.5;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
// Do any additional setup after loading the view, typically from a nib.
}
最佳答案
将其添加到您已发布的代码下面:
[UIView animateWithDuration:5 delay:1 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:4];
animationImageView.frame = CGRectMake(160, 95, 50, 50);
} completion:^(BOOL finished) {
animationImageView.frame = CGRectMake(60, 95, 50, 50);
}];
这将使熊沿着x轴向右移动,花费5秒完成每个动画周期,并重复动画4次。完成每个循环后,它还将动画自动恢复到其原始位置。
如果您不希望它平稳地反转,而是希望在完成每个循环后使其回到原始位置,只需删除
UIViewAnimationOptionAutoreverse
标志。播放显示的选项以获得所需的结果。
关于ios - Objective C动画我想在屏幕上移动动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24092799/