Iphone 同步CCLayer&;UIView动画

Iphone 同步CCLayer&;UIView动画,iphone,ios,cocos2d-iphone,Iphone,Ios,Cocos2d Iphone,我已经在CCLayer上向[[CCDirector sharedDirector]视图]添加了一个表视图作为子视图。然后,我用以下代码分别设置了CCLayer和tableView的动画: 此代码将CCLayer向右和向左移动 -(void)moveHomeScreenLayerWithIsAnimated:(BOOL)_isAnimationRight{ if (!_isAnimationRight) { [mHomeLayer runAction:[CCSequenc

我已经在CCLayer上向[[CCDirector sharedDirector]视图]添加了一个表视图作为子视图。然后,我用以下代码分别设置了CCLayertableView的动画:

此代码将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的x位置首次设置320

//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是uiview的对象

可靠实现同步运动的唯一方法是不使用动作和ui动画。他们只是工作太不一样了

//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*/
}];

而是使用计划更新方法手动更新图层和视图位置。检查移动操作代码,了解如何确保在给定时间内到达某个位置。

我已尝试实现您的代码,但对我无效。