Flip animation when controller pushed on iPhone

送分小仙女□ 提交于 2019-12-18 10:29:40

问题


I had a look around and didn't find what I was exactly looking for.

Is there a way to get a flip animation when pushing a view controller?

I read that you can change the animation by using a modal view controller but AFAIK the animation for a modal view is from bottom to top and that's not what i am looking for. Is there a way to get a flip animation somehow?


回答1:


For modally presented view controllers, you can change the animation with the modalTransitionStyle property. AFAIK, there is no way to change a navigation controller's push animation (except rebuilding UINavigationController from scratch).




回答2:


something like this should work

[UIView beginAnimations:@"animation" context:nil];
[self.navigationController pushViewController: yourviewcontroller animated:NO]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations];

don't forget to set animated to NO when calling pushViewController




回答3:


This also works.. for iOS 4.0 and greater

[UIView  transitionWithView:self.navigationController.view duration:0.8  options:UIViewAnimationOptionTransitionFlipFromLeft
                             animations:^(void) {
                                 BOOL oldState = [UIView areAnimationsEnabled];
                                 [UIView setAnimationsEnabled:NO];
                                 [self.navigationController pushViewController:viewController animated:YES];
                                 [UIView setAnimationsEnabled:oldState];
                             }
                             completion:nil];



回答4:


- (void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:@"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations]; }

in the new viewcontroller will make it flip back the same way (instead of sliding left) when the back button in the toolbar is pushed -- make sure animation is enabled here, e.g., if you make a custom button to pop the stack, use:

- (void) backToPrevious: (id) sender 
{
    //[self.navigationController popViewControllerAnimated:YES];
    [self dismissModalViewControllerAnimated:YES];
}


来源:https://stackoverflow.com/questions/2506647/flip-animation-when-controller-pushed-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!