gpt4 book ai didi

iphone - 一个接一个地运行动画失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:33:03 25 4
gpt4 key购买 nike

我正在尝试为图像设置动画,使其在被选中时左右旋转,基本上是为了让用户了解他们正在触摸的对象。

我找到了一些动画代码:

- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration 
curve:(int)curve degrees:(CGFloat)degrees delay:(CGFloat)delay
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:delay];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];

// The transform matrix
CGAffineTransform transform =
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
image.transform = transform;

// Commit the changes
[UIView commitAnimations];
}

但是,当我尝试运行两个动画时,只有最后一个有效。即使有适当的延迟,也只会显示第二个动画:

[self rotateImage:self duration:.5 
curve:UIViewAnimationCurveEaseIn degrees:60 delay:0];
[self rotateImage:self duration:.5
curve:UIViewAnimationCurveEaseIn degrees:-60 delay:5];

我该怎么做才能创建动画,使其向左旋转,然后向右旋转?

最佳答案

[UIView animateWithDuration:0.2 animations:^{
// animation left
[UIView setAnimationDelay:10];

} completion:^(BOOL finished){

[UIView animateWithDuration:0.2 animations:^{
// animation right
} completion:^(BOOL finished){
// done
}];

}];

在这里找到

https://developer.apple.com/library/content/featuredarticles/Short_Practical_Guide_Blocks/

关于iphone - 一个接一个地运行动画失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9235872/

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