[英]Place UIView back to the original y coordinate when tapped again.
因此,我設置了一個簡單的應用程序來自學iOS中的動畫。 因此,我目前所擁有的只是一個連接到敲擊手勢識別器的UIView。 因此,當您點擊視圖時,它將實現此方法:
-(IBAction)startAnimation:(id)sender
{
[UIView animateWithDuration:3.0 animations:^{
tabView.center = CGPointMake(tabView.center.x, tabView.center.y + 60);
}];
//if tapped again, go back to original y coordinate
}
我的問題是,如何再次將其設置回原來的y坐標位置?
嘗試這個:
// just my example
int i = 0; // static variable
-(IBAction)startAnimation:(id)sender
{
i++;
[UIView animateWithDuration:3.0 animations:^{
if(i%2==1)
tabView.center = CGPointMake(tabView.center.x, tabView.center.y + 60);
else
tabView.center = CGPointMake(tabView.center.x, tabView.center.y - 60);
}];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.