gpt4 book ai didi

ios - 动画 UIButton 向下 - Xcode

转载 作者:可可西里 更新时间:2023-11-01 06:24:55 25 4
gpt4 key购买 nike

我想知道如何在通过

单击时为 UIButton 设置动画
-(IBAction)

提前致谢!

最佳答案

在你的 IBAction

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];

编辑 - 在帧之间切换

在某处初始化 bool 值clicked为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;

}

关于ios - 动画 UIButton 向下 - Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17818349/

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