暂停和恢复“线”增长动画

时间:2013-02-20 06:28:53

标签: ios objective-c core-animation uiviewanimation

The animation I need to implement. Please help me.

我已经尝试了很多方法,但不能顺利完成,我是动画片中的新人,任何帮助都会受到赞赏。

Code I Tried:

我需要添加两个数组的按钮和标签。 eventBtnsPopUpArray和eventLabelsPopUpArray。我尝试在循环中添加它们并且动画不顺畅。

if ([eventBtnsPopUpArray count]>0)
{           

    CABasicAnimation* scalingAnimation;
    scalingAnimation = [CABasicAnimation animationWithKeyPath:@"frame.size"];;
    scalingAnimation.fromValue = [NSNumber numberWithFloat:0];
    scalingAnimation.toValue = [NSNumber numberWithFloat:1024];
    scalingAnimation.duration = 5.0;
    scalingAnimation.cumulative = YES;
    scalingAnimation.removedOnCompletion = NO;
    scalingAnimation.fillMode = kCAFillModeForwards;
    [calendarEventView.layer addAnimation:scalingAnimation forKey:@"rotationAnimation"];


  for (int k=0; k<[eventBtnsPopUpArray count]; k++)
{
    UIButton *btn = [eventBtnsPopUpArray objectAtIndex:0];
    UILabel *lbl = [eventLabelsPopUpArray objectAtIndex:0];



    [UIView animateWithDuration:2
                          delay:0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{

                         [self addSubview:btn];
                         [self addSubview:lbl];

                     }
                     completion:^(BOOL finished){
                         [self pauseLayer:calendarEventView.layer];

                         [self resumeLayer:calendarEventView.layer];
                     }
     ];


}


if (calendarEventView.frame.size.width < 1024) {
    [UIView beginAnimations:@"DrawLineTillEnd" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    calendarEventView.frame = CGRectMake(0, 65, 1024, 7);
    [UIView commitAnimations];
}
}

//暂停和恢复图层功能

    -(void)pauseLayer:(CALayer*)layer
    {
     CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
     layer.speed = 0.0;
    layer.timeOffset = pausedTime;
    }  

    -(void)resumeLayer:(CALayer*)layer
    {
    CFTimeInterval pausedTime = [layer timeOffset];
    layer.speed = 1.0;
    layer.timeOffset = 0.0;
    layer.beginTime = 0.0;
    CFTimeInterval timeSincePause = 
    [layer convertTime:CACurrentMediaTime()  fromLayer:nil] - pausedTime;
    layer.beginTime = timeSincePause;
    }

2 个答案:

答案 0 :(得分:0)

我认为您不需要使用核心动画,只需使用NSTimer并使用更改变量调整UIView的框架(宽度)...检查宽度的简单条件语句(if语句)可以在某一点停止并添加第一个所需的UIButton。单击此按钮将更改BOOLEAN,它将触发NSTimer中的代码继续行增长,直到达到下一个if语句定义的下一个宽度。等

答案 1 :(得分:0)

我不知道如何使用coreplot或coreanimation来做到这一点,但通过视图动画实现这一点非常简单

例如

-(void)animateLine{
   UILabel *labelObj = [[UiLabel alloc]init];
   //Set background image and height of label say 100 pixel
   for(int incrementer = 0; incrementer<100; incrementer ++)
    {
         [UIView beginAnimations:nil context:nil];
         [UIView setAnimationDuration:0.01];
         [labelObj setFrame:cgRectMake(0,100,incrementer,20)];
         [uiview commitAnimation];
    }
}