gpt4 book ai didi

ios - 当通话栏处于事件状态时,自定义 UIViewController 转换设置了错误的 topLayoutGuide 和 bottomLayoutGuide

转载 作者:可可西里 更新时间:2023-11-01 03:00:44 25 4
gpt4 key购买 nike

我有一个 UIViewController 显示另一个 UIViewController。两个 View Controller 都使用带有自动布局的 topLayoutGuidebottomLayoutGuide

一切都很好,有和没有通话栏。或者有或没有自定义过渡...

但是,当有通话栏自定义转换时,我呈现的 View Controller 的 subview 错放了 20px 向下(导致裁剪 View 在底部)。

我检查了一下,是 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];

最佳答案

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

关于ios - 当通话栏处于事件状态时,自定义 UIViewController 转换设置了错误的 topLayoutGuide 和 bottomLayoutGuide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29348568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com