我有一個UIButton設置在故事板上,當按下動畫UIVIew時。我希望同一個按鈕在第二次按下時將UIView動畫/移動回原來的位置。UIButton動作
這樣做的最好方法是什麼?
感謝您的任何幫助或指針。
這是我使用動畫和移動的UIView代碼:
我使用了一個名爲BOOL buttonCurrentStatus。
-(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伊娃保持最後一幀? – Mat
我不明白。你有一個例子,它的設置正確嗎?我非常有興趣學習如何在第一次觸摸時執行一個動作,然後在第二次觸摸時執行不同的動作。謝謝 – hanumanDev
我的意思是你可以使用一個CGRect類變量臨時存儲最後一幀。然後,當您按下按鈕時,只需將按鈕位置重置爲使用的最後一幀。否則,如果結束幀始終相同,請根據需要重新設置sender.frame並重置幀。 (對不起,我在iPad上,如果沒有人回答你,我會盡快完成)。 – Mat