【问题标题】:Synchronising the CCLayer & UIView animation同步 CCLayer 和 UIView 动画
【发布时间】:2013-05-14 06:04:36
【问题描述】:

我在 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 都有动画,但它们的动画不同步。动画持续时间不匹配。有没有其他办法。感谢大家的帮助。

【问题讨论】:

    标签: iphone ios cocos2d-iphone


    【解决方案1】:

    尝试将调用同步到调用位置的两个函数。确保调用之间没有繁重的代码来增加延迟。这可能会对您有所帮助。

    【讨论】:

      【解决方案2】:

      试试这个:

      首先在 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 的一个对象

      【讨论】:

      • 我已尝试实现您的代码,但它对我不起作用。
      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-26
        • 2014-08-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多