我已经成功创建了一个 UIView,它可以播放来自 NSArray 图像的图像动画。我试图让这个图像在动画播放的同时移动。使用 UIView 的 .center 属性不起作用,而且我一定有某种语法错误,我终生无法弄清楚。
原帖:
我正在玩brandontreb的教程。我可以成功地让动画精灵在原地跳舞,但我希望它真正滑过屏幕。亲爱的灵魂可以:
- 请帮我解决我做错了什么以使 UIimage 的中心实际上在屏幕上移动?
- 或者更好的是,将其更新为“动画块”最佳实践?
我一定会花几个小时研究你的修复。
- (IBAction)startWalking:(UIButton *)sender {
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
nil];
UIImageView * ryuJump = [[UIImageView alloc] initWithFrame:
CGRectMake(100, 125, 150, 130)];
ryuJump.animationImages = imageArray;
ryuJump.animationDuration = 1.1;
ryuJump.animationRepeatCount=5;
CGPoint p = ryuJump.center;
p.x += 100;
ryuJump.center = p;
[UIView animateWithDuration:20
delay:0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
ryuJump.center = CGPointMake(p.x, p.y);
}
completion:^(BOOL finished){
}];
ryuJump.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:ryuJump];
[ryuJump startAnimating];
}