gpt4 book ai didi

ios - UIButton 动画被跳过

转载 作者:行者123 更新时间:2023-11-28 22:33:31 25 4
gpt4 key购买 nike

我为我的按钮实现了滑入屏幕的动画。如果按钮已经在屏幕内,我希望我的按钮先滑到外面,然后再滑回来。

然而,第一个动画(当按钮已经滑入屏幕时)被跳过,因此按钮只是立即跳出屏幕然后向后滑动。

我想让它们慢慢地滑到外面,然后再慢慢地滑回来。

它有点像 if 子句中的 setAnimationDuration 被忽略:

[self.buttonInfoFrame setAlpha:1.0];
[self.buttonSetCourse setAlpha:1.0];
[self.buttonSetCourse setEnabled:YES];

if(![self.selected isEqual: @""])
{
CGRect frame = self.buttonInfoFrame.frame;
frame.origin.x = 1050;
frame.origin.y = 150;

CGRect frame2 = self.buttonSetCourse.frame;
frame2.origin.x = 1050;
frame2.origin.y = 526;

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

self.buttonInfoFrame.frame = frame;
self.buttonSetCourse.frame = frame2;

[UIView commitAnimations];
}

CGRect frame = self.buttonInfoFrame.frame;
frame.origin.x = 757;
frame.origin.y = 150;

CGRect frame2 = self.buttonSetCourse.frame;
frame2.origin.x = 747;
frame2.origin.y = 526;

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

self.buttonInfoFrame.frame = frame;
self.buttonSetCourse.frame = frame2;

[UIView commitAnimations];

最佳答案

在第一个动画的完成 block 中编写你的第二个动画!

编辑

   if(![self.selected isEqual: @""])
{
CGRect frame = self.buttonInfoFrame.frame;
frame.origin.x = 1050;
frame.origin.y = 150;

CGRect frame2 = self.buttonSetCourse.frame;
frame2.origin.x = 1050;
frame2.origin.y = 526;

[UIView animateWithDuration:1,0 delay:0.0 options:option
animations:^{
self.buttonInfoFrame.frame = frame;
self.buttonSetCourse.frame = frame2;
}
completion:^(BOOL finished){
CGRect frame = self.buttonInfoFrame.frame;
frame.origin.x = 757;
frame.origin.y = 150;

CGRect frame2 = self.buttonSetCourse.frame;
frame2.origin.x = 747;
frame2.origin.y = 526;

[UIView animateWithDuration:1.0 delay:0.0 options:option
animations:^{
self.buttonInfoFrame.frame = frame;
self.buttonSetCourse.frame = frame2;
}
completion:nil];
}];

} else {

CGRect frame = self.buttonInfoFrame.frame;
frame.origin.x = 757;
frame.origin.y = 150;

CGRect frame2 = self.buttonSetCourse.frame;
frame2.origin.x = 747;
frame2.origin.y = 526;

[UIView animateWithDuration:1.0 delay:0.0 options:option
animations:^{
self.buttonInfoFrame.frame = frame;
self.buttonSetCourse.frame = frame2;
}
completion:nil];
}];
}

关于ios - UIButton 动画被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16760300/

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