gpt4 book ai didi

iphone - UIView两个动画共存

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:12:21 26 4
gpt4 key购买 nike

如何让一个动画在调用第二个动画后永远继续?例如:

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){
}];

最佳答案

您将无法使用此处提供的基于 block 的动画来执行此操作。您需要使用带有 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:

关于iphone - UIView两个动画共存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com