How to store animations in obj-c?

147 views Asked by At

I've got 2 methods in my class and in each I've got an animation. My question is, can I store these animations in one array or something and refer to them by beginAnimation:name? If yes, how can I do this?

thanks for help

-(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

There are 1 answers

0
Filip Radelic On BEST ANSWER

You can't store UIView animations as they are not objects. Even with blocks animation api introduced in 4.0, animations are still just actions performed by static class methods. Closest thing you can do is store the blocks and reuse them, or just do what you are doing and keep compatibility with iOS versions older than 4.0.

If you really want to store your animations as objects, you should skip UIView animation and go a bit lower to Core Animation.