我已经成功创建了一个UIView,它可以播放来自NSArray图像的图像动画。我试图让这个图像在动画播放的同时移动。使用UIView的.center属性是行不通的,我必须有一些语法错误,我不能为我的生活弄清楚。
原帖:
我正在玩brandontreb的教程。我可以成功地让动画精灵在舞台上跳舞,但我希望它实际上可以在屏幕上滑动。亲爱的灵魂可以:
我肯定会研究你的修复工作几个小时。
- (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];
}
答案 0 :(得分:3)
卸下:
ryuJump.center = p;
你基本上是在告诉uiview动画到你刚设置的完全相同的位置(所以不会发生任何事情)。