UIView两个动画同时存在

3
如何在调用第二个动画后使一个动画持续不断呢?例如:
1)开始让一个对象脉动
2)在它脉动时移动它
3)它继续脉动
所有的东西都可以工作,除了第二个动画无限期地停止第一个动画。以下是一些示例代码:
//Pulsate **

        [UIView animateWithDuration:0.25
                              delay:0
                            options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat)
                         animations:^{
                             CGAffineTransform currentTransform = self.transform;
                             CGAffineTransform newTransform1 = CGAffineTransformScale(currentTransform, .95, .95);
                             [self setTransform:newTransform1];
                             CGAffineTransform newTransform2 = CGAffineTransformScale(currentTransform, 1, 1);
                             [self setTransform:newTransform2];
                         } 
                         completion:nil];    


//Move **
     [UIView animateWithDuration:0.30
                      delay:0
                    options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState )
                 animations:^{
                     [[(UIPinchGestureRecognizer*)sender view] setCenter:CGPointMake(myAppDelegate.MCViewReference.center.x-300, myAppDelegate.MCViewReference.center.y)];
                 } 
                 completion:^(BOOL finished){
                }];    
2个回答

5
你不能直接使用这里的块状动画来实现此操作。你需要使用显式动画 CABasicAnimation 来拆分你的动画。创建一个用于脉冲效果的动画,并将其设置为无限重复。然后,你可以通过设置中心点(动态或非动态)来移动它。
CABasicAnimation *pulsation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulsation.fromValue = [NSNumber numberWithFloat:0.95f];
pulsation.toValue = [NSNumber numberWithFloat:1.f];
pulsation.duration = 0.25f;
pulsation.autoreverses = YES;
pulsation.repeatCount = INFINITY;

[self.layer addAnimation:pulsation forKey:@"pulse"];

一旦将动画添加到图层中,它将开始动画。要删除动画,只需调用[self.layer removeAnimationForKey:@"pulse"removeAllAnimations:


1
你可以将动画分成阶段,并使用完成块来启动下一个阶段。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接