Animation of buttons in the navigation controller

CAT transitions can be used to animate transitions in navigation controllers while drilling. However, when you use the back and navigation buttons (backward), the animation is still disabled. Does anyone know how to connect the CAT transition to the Back button on the navigation controller? thanks.

The code used for the animation when drilling is:

CATransition *transition = [CATransition animation]; transition.duration = 1; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionPush; transition.subtype = kCATransitionFromTop; transition.delegate = self; [self.navigationController.view.layer addAnimation:transition forKey:nil]; 
+4
source share
5 answers

There is no need to create a custom button ... You can just do something like this:

 - (void)viewWillDisappear:(BOOL)animated { if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // back button was pressed. We know this is true because self is no longer // in the navigation stack. CATransition *transition = [CATransition animation]; [transition setDuration:0.75]; [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [transition setType:@"oglFlip"]; [transition setSubtype:kCATransitionFromLeft]; [transition setDelegate:self]; [self.navigationController.view.layer addAnimation:transition forKey:nil]; } [super viewWillDisappear:animated]; } 

Edit: you must first add a quartz structure in order to use CATransition

+7
source

To add animation to the "Back" button, you need to create your own "Back" button, and when you click the "Back" button, specify the desired animation.

  • Adding a return button to the navigation bar: add this line to your viewDidLoad method:

     self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(back)]; 
  • In the reverse method, add this code:

     CATransition *transition = [CATransition animation]; transition.duration = 1; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionPush; transition.subtype = kCATransitionFromBottom; transition.delegate = self; [self.navigationController.view.layer addAnimation:transition forKey:nil]; [self.navigationController popViewControllerAnimated:YES]; 
+6
source

I'm not sure I understand this question. UINavigationController already uses slide transition when switching views. If you want to add a custom transition to the back button, you will have to create a custom back button and connect it to the action that will run your CATransition code.

0
source

If you want an animation like the back button on the navigator control panel to just put the following code into action.

[self.navigationController popViewControllerAnimated: YES];

0
source

Swift 3 version of shadowfax answer:

  let transition:CATransition = CATransition.init() transition.duration = 0.75 transition.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut) transition.type = "oglFlip" transition.subtype = kCATransitionFromRight //transition.delegate = self // not needed self.navigationController?.view.layer.add(transition, forKey:nil) 
0
source

Source: https://habr.com/ru/post/1314286/


All Articles