2011-12-13 87 views
0

我在課堂上有兩種方法,每種都有動畫。我的問題是,我可以將這些動畫存儲在一個數組中或通過beginAnimation引用它們:name?如果是的話,我該怎麼做?如何在obj-c中存儲動畫?

感謝您的幫助

-(void)hideMenu{ 
    [UIView beginAnimations:@"HIDE_MENU" context:nil]; 
    [UIView setAnimationDuration:0.38]; 
    [UIView setAnimationDelay:0.12]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.frame = CGRectMake(0, -1 * self.frame.size.height, self.frame.size.width, self.frame.size.height); 
    [UIView commitAnimations]; 
} 

-(void)showMenu{ 
    [UIView beginAnimations:@"SHOW_MENU" context:nil]; 
    [UIView setAnimationDuration:0.38]; 
    [UIView setAnimationDelay:0.12]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); 
    [UIView commitAnimations]; 
} 

-(void)handleShowMenu:(NSNotification*)note{ 
    [self showMenu]; 
} 

-(void)handleHideMenu:(NSNotification*)note{ 
    [self hideMenu]; 
} 

回答

1

不能存儲的UIView動畫,因爲它們不是對象。即使在4.0中引入了blocks animation api,動畫仍然只是靜態類方法執行的動作。你可以做的最接近的事情是存儲塊並重用它們,或者只是做你正在做的事情,並保持與4.0以前的iOS版本的兼容性。

如果您確實想將動畫存儲爲對象,則應該跳過UIView動畫並稍微降低至Core Animation

+0

謝謝你,我閱讀了Core Animation。 – 2011-12-14 07:28:56