Back Button Animation in Navigation Controller

后端 未结 5 1827
执笔经年
执笔经年 2021-02-10 19:39

CATransitions can be used to animate transitions in Navigation Controllers when drilling down. However when using Back button og Navigation Controller (going back up) animation

5条回答
  •  一个人的身影
    2021-02-10 19:50

    There is no need to create a custom button... You can simply 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 add the quartz framework first in order to use CATransition

提交回复
热议问题