Достижение этого эффекта с использованием API перехода контроллера представления, представленного в iOS 7, является относительно простым.
Мы будем использовать обычные методы UIViewControllerTransitioningDelegate для определения анимации. Сначала мы создадим объект «аниматор», который будет имитировать стандартную анимацию слайдов UINavigationController.
// UIViewControllerAnimatedTransitioning
@interface PushPopAnimator : NSObject <UIViewControllerAnimatedTransitioning>
@property (assign, nonatomic, getter=isPresenting) BOOL presenting;
@end
@implementation PushPopAnimator
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
return 0.35;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
UIView *animatingView = self.isPresenting ? toVC.view : fromVC.view;
CGRect offsetFrame = CGRectOffset(container.frame, CGRectGetWidth(container.frame), 0);
CGRect finalFrame = self.isPresenting ? container.frame : offsetFrame;
if (self.isPresenting) {
animatingView.frame = offsetFrame;
[container addSubview:animatingView];
}
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0.0
usingSpringWithDamping:0.9
initialSpringVelocity:2.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
animatingView.frame = finalFrame;
} completion:^(BOOL finished) {
BOOL cancelled = [transitionContext transitionWasCancelled];
[transitionContext completeTransition:!cancelled];
if (self.isPresenting && toVC.navigationController) {
[container insertSubview:fromVC.view belowSubview:toVC.view];
} else if (fromVC.navigationController && cancelled) {
[container insertSubview:toVC.view belowSubview:fromVC.view];
}
}];
}
@end
внутри класса viewController
- (IBAction)pushModal:(UIButton *)sender {
[self.navigationController pushViewController:[self modalController] animated:YES];
}
- (UIViewController *)modalController {
UIViewController *modal = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ModalViewController class])];
modal.modalPresentationStyle = UIModalPresentationCustom;
modal.transitioningDelegate = self;
return modal;
}
#pragma mark - UIViewControllerTransitioningDelegate
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
return [self pushPopAnimatorForPresentation:YES];
}
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
return [self pushPopAnimatorForPresentation:NO];
}
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
return [self pushPopAnimatorForPresentation:operation == UINavigationControllerOperationPush];
}
- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController {
return self.interactionController;
}
Для справки: https://medium.com/@A2HGO/blurred-translucent-ios-navigation-controller-transitions-f38934204f46#.fwggl81td