如何设置导航转场动画(Navigation转场)

1.首先,让Controller遵守NavigationController代理。

self.navigationController.delegate=self;

写完这句话之后发现要遵守协议

2.然后点进去协议,实现方法

- (nullableid)navigationController:(UINavigationController*)navigationController

animationControllerForOperation:(UINavigationControllerOperation)operation

fromViewController:(UIViewController*)fromVC

toViewController:(UIViewController*)toVC  {

returnself;

}

注意此处可以return self,也可以return别的,来作为转场动画器;

3.写完上面的方法,发现要遵守协议

遵守完协议,发现有方法要实现

- (NSTimeInterval)transitionDuration:(nullableid)transitionContext{

return1;

}

- (void)animateTransition:(id)transitionContext{

UIView*containerView = [transitionContextcontainerView];

UIViewController*toVC = [transitionContextviewControllerForKey:UITransitionContextToViewControllerKey];

[containerViewaddSubview:toVC.view];

toVC.view.alpha=0;

[UIViewanimateWithDuration:[selftransitionDuration:transitionContext]animations:^{

toVC.view.alpha=1;

}completion:^(BOOLfinished) {

[transitionContextcompleteTransition:YES];

}];

}

上述两个方法,一个是给出动画执行的时间,第二个是动画具体执行的动作

之后就可以实现转场动画了。

你可能感兴趣的:(如何设置导航转场动画(Navigation转场))