我正在开发一个水族馆应用程序。我需要在其中产生鱼的运动。鱼应该游泳,当到达水族箱的一端时,应该转弯(或翻转)并移动到另一端,再转一圈(或翻转)并回到原来的位置。
鱼forword运动正常工作它也转到(翻转)到达终点。但当它到达另一端时,翻转动画加上进一步的动画突然跳过。
以下是我正在使用的代码.....
CGFloat originalChildXpos = fishView.frame.origin.y;
/************************************** Animation 1 **************************************************************/
[UIView animateWithDuration:15.0
delay:1.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame =CGRectMake(0, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
/*********************************** Animation 2 ****************************************************************/
[UIView animateWithDuration:2.4
delay:3.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0));
}completion:NULL];
/********************************* Animation 3 ****************************************************************/
[UIView animateWithDuration:10
delay:3.4
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame = CGRectMake(-aquariumView.frame.size.width, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
/*************************************** Animation 4 *****************************************************/
[UIView animateWithDuration:1.4
delay:13.4
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(-M_PI, 0.0, 1.0, 0.0));
}completion:NULL];
/************************************* Animation 5 *******************************************/
[UIView animateWithDuration:13.8
delay:2.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame = CGRectMake(originalChildXpos, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
我想我在使用CATransform3DGetAffineTransform(CATransform3DMakeRotation())
功能的时候错过了一些东西,第二次翻转......
这里的任何人都能告诉我解决方法并解释我的错误
我还想知道在使用CATransform3D
进行旋转时,相对于视图的坐标轴是否应用了变换或受到影响?
答案 0 :(得分:0)
CGFloat originalChildXpos = fishView.frame.origin.y;
CGAffineTransform currentTransform=fishView.transform; // step one add this
/************************************** Animation 1 **************************************************************/
[UIView animateWithDuration:15.0
delay:1.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame =CGRectMake(0, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
/*********************************** Animation 2 ****************************************************************/
[UIView animateWithDuration:2.4
delay:3.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0));
}completion:NULL];
/********************************* Animation 3 ****************************************************************/
[UIView animateWithDuration:10
delay:3.4
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame = CGRectMake(-aquariumView.frame.size.width, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
/*************************************** Animation 4 *****************************************************/
[UIView animateWithDuration:1.4
delay:13.4
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.transform = currentTransform; // step 2 replace here
}completion:NULL];
/************************************* Animation 5 *******************************************/
[UIView animateWithDuration:13.8
delay:2.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fishView.frame = CGRectMake(originalChildXpos, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
}completion:NULL];
对于变换你在初始时确实是x = y所以现在你的x变成了y 在下一个陈述中你改变了y = y所以没有效果......