クリックしたときにUIButtonを下にアニメーション化する方法を知りたかった
-(IBAction)
前もって感謝します!
クリックしたときに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
どこかでブール値を 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;
}