gpt4 book ai didi

ios - 如何一个接一个地在单个 subview 上应用 2 个动画

转载 作者:行者123 更新时间:2023-11-28 19:39:38 24 4
gpt4 key购买 nike

我有一个代表收藏按钮的按钮。我想以 1.0 秒的延迟向上动画,然后在有人单击它时以 0.2 秒的延迟向下动画。我做了两种不同的方法来做向上和向下的动画。但是当我实际运行代码时,两个动画同时提交,这显示了相反的顺序。我想先为向上动画制作动画,然后为向下动画制作动画。这是代码。

-(void)starButtonUpAnimation{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];

CGRect frame = self.starButton.frame;
frame.origin.y = frame.origin.y - frame.size.height;
self.starButton.frame = frame;

[UIView commitAnimations];

}

-(void)starButtonDownAnimation{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];

CGRect frame1 = self.starButton.frame;
frame1.origin.y = frame1.origin.y + frame1.size.height;
self.starButton.frame = frame1;
[UIView commitAnimations];

}

我调用上述方法的按钮操作方法。

- (IBAction)clickedStarButton:(id)sender {
[self starButtonUpAnimation];
[self changeStarButtonImage];

[self starButtonDownAnimation];
}

最佳答案

是这样的吗?

-(void)starButtonUpAnimation{

CGRect frame = self.starButton.frame;
frame.origin.y = frame.origin.y - frame.size.height;
self.starButton.frame = frame;
}


-(void)starButtonDownAnimation{


CGRect frame1 = self.starButton.frame;
frame1.origin.y = frame1.origin.y + frame1.size.height;
self.starButton.frame = frame1;

}

- (IBAction)clickedStarButton:(id)sender {

[UIView animateWithDuration:2.0 animations:^{
[self starButtonUpAnimation];
} completion:^(BOOL finished) {
[self changeStarButtonImage];
[UIView animateWithDuration:0.1 animations:^{
[self starButtonDownAnimation];
} completion:^(BOOL finished) {
// clean up
}];
}];
}

关于ios - 如何一个接一个地在单个 subview 上应用 2 个动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35282068/

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