Просмотр содержимого родительского просмотра при использовании show (push) segue - PullRequest
0 голосов
/ 06 ноября 2019

В моем случае у меня есть представление в новом контроллере представления, я хочу, чтобы, когда эта страница была открыта, фон этого представления имел 50% альфа. Как правило, я могу использовать модально представленный вид перехода, затем я легко могу изменить альфа-фон, чтобы увидеть содержимое родительского представления. Теперь, по какой-то причине, я должен сделать это с помощью show (push) вида segue, и мне все еще нужно изменить фоновую альфа, чтобы увидеть содержимое родительского представления. Возможно ли это?

Большое спасибо

вот один скриншот с видами, задний фон должен быть четким

screenshot

1 Ответ

0 голосов
/ 06 ноября 2019

Достижение этого эффекта с использованием 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

...