同步CCLayer&UIView动画
问题描述:
我通过CCLayer添加了一个tableView作为子视图到[[CCDirector sharedDirector]视图]。然后,我有动画的CCLayer & 的tableView分别用以下代码:同步CCLayer&UIView动画
本规范移动CCLayer到&左的权利。
-(void)moveHomeScreenLayerWithIsAnimated:(BOOL)_isAnimationRight{
if (!_isAnimationRight) {
[mHomeLayer runAction:[CCSequence actionOne:[CCDelayTime actionWithDuration:0.0f] two:[CCMoveTo actionWithDuration:0.4f position:ccp((size.width/4)*3, 0)]]];
}
else{
[mHomeLayer runAction:[CCSequence actionOne:[CCDelayTime actionWithDuration:0.0f] two:[CCMoveTo actionWithDuration:0.4f position:ccp(0, 0)]]];
}
}
而对于的tableView的动画:
-(void)ViewAnimationRight{
[UIView cancelPreviousPerformRequestsWithTarget:self];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
tableViewHome.frame = CGRectMake(size.width - size.width/4,topBar.contentSize.height, size.width, size.height);
[tableViewHome setScrollEnabled:NO];
[UIView commitAnimations ];
}
-(void)ViewAnimationLeft{
[UIView cancelPreviousPerformRequestsWithTarget:self];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
tableViewHome.frame = CGRectMake(0, topBar.contentSize.height, size.width, size.height);
[tableViewHome setScrollEnabled:YES];
[UIView commitAnimations ];
}
无论是CCLayer &的tableView被动画,但是他们的动画不同步。动画持续时间不匹配。有没有其他的方法。大家的帮助表示赞赏。
答
尝试将呼叫同步到呼叫地点的两个功能。确保在通话之间没有繁重的代码来添加延迟。这可能会帮助你。
答
试试这个:
先在你的UIView
//right to left animation
CGRect basketTopFrame = basketTop.frame;
basketTopFrame.origin.x = 0;
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ basketTop.frame = basketTopFrame; } completion:^(BOOL finished){
}];
//left to right animation
CGRect napkinBottomFrame = basketTop.frame;
napkinBottomFrame.origin.x = 320;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ basketTop.frame = napkinBottomFrame; } completion:^(BOOL finished)
{
/*done*/
}];
basketTop的x位置设置320是你的UIView
答
的唯一方法的目的是可靠地实现synchroneous运动是不使用动作和用户动画。他们只是工作太不同了。
取而代之的是更新图层并以预定的更新方法手动查看位置。检查移动操作代码,了解如何确保在给定时间内达到某个位置。
我试着实现你的代码,但它没有为我工作。 – Pranoy 2013-05-14 07:33:31