0
我在CAKeyFrameAnimation上遇到了一个奇怪的问题。iOS CAKeyframeAnimation奇怪的图像旋转
下面的代码:
//Inside the selector method of the button
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[anim setDelegate:self];
anim.path = racetrack.path;
anim.rotationMode = kCAAnimationRotateAuto;
anim.repeatCount = 0;
anim.duration = 10.0;
[carBtn.layer addAnimation:anim forKey:@"race"];
动画工作正常。 按下carBtn(带汽车背景图像的按钮)时会出现问题。 按钮的图像无故地旋转180°(至少没有理由)。 我已经对自己与创建动画
carBtn.transform = CGAffineTransformMakeRotation(M_PI);
后,这行代码旋转按钮,而是为了一两秒钟(动画开始之前)汽车是相反面对其初始位置。按钮是这样创建的:
UIImage* car = [UIImage imageNamed:@"car_image"];
carBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[carBtn setFrame:CGRectMake(startPoint.x-45, startPoint.y-33, macchina.size.width, macchina.size.height)];
[carBtn setBackgroundImage:car forState:UIControlStateNormal];
[carBtn setBackgroundImage:car forState:UIControlStateHighlighted];
[carBtn addTarget:self action:@selector(carPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:carBtn];
这怎么可能? 谢谢
感谢您的帮助。不幸的是,在我的情况下,您链接的解决方案无效。我试图使用Caleb的“animate”方法,但UIView animationWithDuration块的持续时间不起作用。虽然我将持续时间设置为10秒,但汽车在小于1秒的时间内绕着路径移动。有关这个问题的任何建议? – nicopasso 2013-02-10 19:10:41
我认为这个问题是我沿着负x坐标的路径的方向。所以我创建了沿着正x坐标的第一个运动的反向路径。但问题依然存在。按钮(或图像)在动画开始之前旋转180°。令人沮丧! – nicopasso 2013-02-10 20:41:31