某些场景下需要push的动画是present方式的,或者present的动画是push方式的。
<CAAnimationDelegate>
/**
push,以模态的方式弹出
*/
- (void)wzl_pushViewController:(UIViewController *)controller animated:(BOOL)animated {
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:controller animated:NO];
}
/**
push,以模态的方式退出
*/
- (void)wzl_popViewControllerAnimated:(BOOL)animated {
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
}
/**
push,popToRoot以模态的方式退出
*/
- (void)wzl_popToRootViewControllerAnimate:(BOOL)animated{
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
}
/**
present,以push的方式推出
*/
- (void)wzl_presentViewController:(UIViewController *)controller animated:(BOOL)animated completion:(void(^)(void))completion {
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[[[UIApplication sharedApplication].keyWindow layer]addAnimation:transition forKey:nil];
[self presentViewController:controller animated:NO completion:completion];
}
/**
present,以push的方式退出
*/
- (void)wzl_dismissViewControllerAnimated:(BOOL)animated completion:(void(^)(void))completion {
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromLeft;
[[[UIApplication sharedApplication].keyWindow layer]addAnimation:transition forKey:nil];
[self dismissViewControllerAnimated:NO completion:completion];
}