我在 CCLayer 上添加了一个 tableView 作为子视图到[[ CCDirector sharedDirector ]view]。然后我使用以下代码分别为CCLayer和tableView设置了动画:
此代码将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 都有动画,但它们的动画不同步。动画持续时间不匹配。有没有其他办法。感谢大家的帮助。