简体   繁体   中英

How to store animations in obj-c?

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];
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM