Ios 设置UIButton向下的动画-Xcode
我想知道当点击via时,我将如何设置ui按钮的动画Ios 设置UIButton向下的动画-Xcode,ios,uibutton,jquery-animate,ibaction,Ios,Uibutton,Jquery Animate,Ibaction,我想知道当点击via时,我将如何设置ui按钮的动画 -(IBAction) 提前谢谢 在您的iAction UIButton *button = (UIButton*)sender; //animates button 25 pixels right and 25 pixels down. Customize CGRect newFrame = CGRectMake(button.frame.origin.x + 25, button.frame.origin.y + 25, button.
-(IBAction)
提前谢谢 在您的
iAction
UIButton *button = (UIButton*)sender;
//animates button 25 pixels right and 25 pixels down. Customize
CGRect newFrame = CGRectMake(button.frame.origin.x + 25, button.frame.origin.y + 25, button.frame.size.width, button.frame.size.height);
[UIView animateWithDuration:0.3f
delay:0.0f
options: UIViewAnimationOptionCurveLinear
animations:^{
[button setFrame:newFrame];
}
completion:nil];
编辑-在帧之间切换
将布尔值单击的初始化为NO
if (!clicked){
//animates button 25 pixels right and 25 pixels down. Customize
CGRect newFrame = CGRectMake(button.frame.origin.x + 25, button.frame.origin.y + 25, button.frame.size.width, button.frame.size.height);
[UIView animateWithDuration:0.3f
delay:0.0f
options: UIViewAnimationOptionCurveLinear
animations:^{
[button setFrame:newFrame];
}
completion:nil];
clicked = YES;
} else {
//animates button 25 pixels left and 25 pixels up. Customize
CGRect newFrame = CGRectMake(button.frame.origin.x - 25, button.frame.origin.y - 25, button.frame.size.width, button.frame.size.height);
[UIView animateWithDuration:0.3f
delay:0.0f
options: UIViewAnimationOptionCurveLinear
animations:^{
[button setFrame:newFrame];
}
completion:nil];
clicked = NO;
}
对iAction中的哪些内容将使按钮动画化?您所说的“使UIButton动画化”是什么意思?你的意思是将按钮的框架设置为一个新位置吗?是的。这正是我要寻找的。我如何将其放在if-else语句中,这样当第一次单击按钮时,它会移动位置,然后再次单击时,它会向上移动如果你只是来回切换,你可以在条件中检查按钮框架,或者设置一个布尔标志OK…我不知道如何用布尔来表示。请您编辑答案,将其包括在内好吗?在.m文件顶部的yourViewController()
之后添加{}
括号,并在这些括号中放入BOOL clicked代码>。然后在viewDidLoad中添加行clicked=NO代码>布尔逻辑和布尔逻辑对于任何语言的编程和开发都非常重要,因此我建议您在尝试做任何过于复杂的事情之前,先阅读一下布尔逻辑和其他一些基本的东西,您只会一直感到沮丧。:)