我想知道当点击时如何使 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];
编辑 - 在帧之间切换
初始化布尔值clicked
到某处不
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)