我有一个UIViewController
介绍另一个UIViewController
。两个视图控制器都使用topLayoutGuide
自动bottomLayoutGuide
布局。
一切都很好,有和没有通话栏。或者有或没有自定义过渡......
但是,当有一个通话栏和一个自定义转换时,我呈现的视图控制器的子视图错位了 20 像素(导致底部的剪辑视图)。
我查了一下,是那个topLayoutGuide
和bottomLayoutGuide
哪个放错了……
这是转换的代码:
#pragma mark - GETTER
- (CGFloat)presentationTopProgressValue {
return __fromViewControllerView.y / __containerView.height;
}
#pragma mark - SETTER
- (void)set_context:(id<UIViewControllerContextTransitioning>)_context {
__context = _context;
__containerView = [__context containerView];
__fromViewController = [__context viewControllerForKey:UITransitionContextFromViewControllerKey];
__fromViewControllerView = [__fromViewController view];
__toViewController = [__context viewControllerForKey:UITransitionContextToViewControllerKey];
__toViewControllerView = [__toViewController view];
}
#pragma mark - TRANSITION
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
return self;
}
#pragma mark - ANIMATING
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
self._context = transitionContext;
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:__containerView];
UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[__fromViewControllerView]];
gravityBehavior.gravityDirection = CGVectorMake(0, 5.0f);
__weak typeof(self) weakSelf = self;
gravityBehavior.action = ^{
typeof(self) strongSelf = weakSelf;
if ([strongSelf presentationTopProgressValue] > 1.0) {
[animator removeAllBehaviors];
[strongSelf._context completeTransition:YES];
strongSelf._context = nil;
}
};
[__containerView addSubview:__toViewControllerView];
[__containerView addSubview:__fromViewControllerView];
[animator addBehavior:gravityBehavior];
}
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
return 0.2f;
}
这是演示的代码:
MPProfileViewController *next = [MPProfileViewController new];
MPNavigationController *nav = [[MPNavigationController alloc] initWithRootViewController:next];
#warning - The transition delegate create a wrong margin layout when in-call bar is active
nav.modalPresentationStyle = UIModalPresentationFullScreen;
nav.transitioningDelegate = __dragToDismiss;
[self.navigationController presentViewController:nav animated:YES completion:nil];