当调用栏处于活动状态时,自定义UIViewController转换设置错误的topLayoutGuide和bottomLayoutGuide

时间:2015-03-30 14:15:09

标签: ios uiviewcontroller autolayout transitions in-call

我有一个UIViewController呈现另一个UIViewController。 两个视图控制器都使用topLayoutGuidebottomLayoutGuide使用自动布局。

一切都很好,无论是否有通话吧。或者有或没有自定义过渡...

但是,当有一个调用栏一个自定义转换时,我呈现的视图控制器的子视图放错了20px(导致剪切视图)在底部)。

我查了一下,topLayoutGuidebottomLayoutGuide错位了......

这里是过渡的代码:

#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];

1 个答案:

答案 0 :(得分:0)

为视图层次结构创建视图时,应始终设置视图的自动调整大小属性。当视图控制器显示在屏幕上时,其根视图通常被调整大小以适合可用空间,该可用空间可以根据窗口的当前方向和诸如状态栏的其他界面元素的存在而变化。您可以使用检查器窗口在Interface Builder中配置自动调整属性,也可以通过修改每个视图的autoresizesSubviews和autoresizingMask属性以编程方式配置。如果视图控制器同时支持纵向和横向,则设置这些属性也很重要。在方向更改期间,系统使用这些属性自动重新定位和调整视图大小以匹配新方向。如果视图控制器支持自动布局并且是另一个视图控制器的子视图,则应调用视图的setTranslatesAutoresizingMaskIntoConstraints:方法来禁用这些约束。