我尝试了很多方法但无法顺利完成,我是动画中的新手,任何帮助将不胜感激。
我试过的代码:
我需要在两个数组中添加按钮和标签。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;
}