【发布时间】:2012-11-18 11:46:34
【问题描述】:
我在情节提要中设置了一个 UIButton,当按下它时,它会为 UIVIew 设置动画。我希望在第二次按下 UIView 时,使用相同的按钮将其设置为动画/移动回原点。
最好的方法是什么?
感谢任何帮助或指点。
这是我用来动画和移动 UIVIew 的代码:
我正在使用一个名为 buttonCurrentStatus 的 BOOL。
-(IBAction)sortDeals:(UIButton*)sender {
if (buttonCurrentStatus == NO)
{
buttonCurrentStatus = YES;
CGRect menuTopFrame = self.menuTop.frame;
menuTopFrame.origin.y = 30;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.menuTop.frame = menuTopFrame;
[UIView commitAnimations];
NSLog(@"Sort Deals touched button status = yes");
} else {
buttonCurrentStatus = NO;
CGRect menuTopFrame = self.menuTop.frame;
menuTopFrame.origin.y = 30;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.menuTop.frame = menuTopFrame;
[UIView commitAnimations];
NSLog(@"Sort Deals touched button status = no");
}
【问题讨论】:
-
CGRect ivar 不够保留最后一帧?
-
我不明白。你有一个正确设置的例子吗?我真的很想学习如何在第一次触摸时让按钮执行一个动作,然后在第二次触摸时执行不同的动作。谢谢
-
我的意思是你可以使用一个CGRect类变量来临时存储最后一帧。然后,当您重新点击按钮时,只需将按钮位置重置为使用的最后一帧。否则,如果结束帧始终相同,请检查 sender.frame 并根据您的要求重置帧。 (对不起,我在 iPad 上,如果没有人回答你,我会尽快做)。
-
@hanumanDev 您可以使用 BOOL 来存储当前状态并在每次按下按钮时翻转 bool。
-
等我回家再给你一个代码示例,如果到时候没人有的话。
标签: iphone objective-c ios ibaction