如何在obj-c中存储动画?

时间:2011-12-13 21:59:00

标签: ios objective-c methods storage commitanimations

我班上有2个方法,每个方法都有动画。我的问题是,我可以将这些动画存储在一个数组或其他内容中,并通过beginAnimation:name来引用它们吗?如果是,我该怎么做?

感谢您的帮助

-(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 个答案:

答案 0 :(得分:1)

您无法存储UIView动画,因为它们不是对象。即使在4.0中引入了blocks animation api,动画仍然只是由静态类方法执行的动作。您可以做的最近的事情是存储块并重复使用它们,或者只是执行您正在执行的操作并保持与早于4.0的iOS版本的兼容性。

如果您真的想将动画存储为对象,则应跳过UIView动画并稍微降低到Core Animation