gpt4 book ai didi

ios - UIViewControllerAnimatedTransitioning 在 iPhone X 上插入安全区域

转载 作者:可可西里 更新时间:2023-11-01 04:23:07 24 4
gpt4 key购买 nike

当在转换委托(delegate)上调用 animateTransition 时,尚未在“to view controller”上设置 Safe Area Insets。

我尝试通过调用以下方法强制布局:toViewController.view.setNeedsLayout()toViewController.view.layoutIfNeeded() 但没有成功。

任何人都可以建议一种方法来强制提前设置安全区域插图或确定我应该如何及时知道插图以使过渡正常工作。

效果是我有一个 UICollectionViewCell,一旦转换完成,它就会向下移动。这是因为框架最初有一个 0,0 原点,而不是在 iPhone X 上说 0,44 ,一旦设置了安全区域插入,它最终就会有,转换将在哪个时间完成。

最佳答案

当您调用 layoutIfNeeded 时,确保目标 View Controller 实际上位于 View 层次结构中。我有同样的问题,奇怪的是只影响某些方向,并通过在下面添加第二行和第三行来修复它:

UIViewController * toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

// Added these two lines:
toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController];
[transitionContext.containerView addSubview:toViewController.view];

[toViewController.view setNeedsLayout];
[toViewController.view layoutIfNeeded];

关于ios - UIViewControllerAnimatedTransitioning 在 iPhone X 上插入安全区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624676/

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