gpt4 book ai didi

ios - UIViewController 在模式呈现后更改尺寸

转载 作者:行者123 更新时间:2023-11-29 05:40:51 26 4
gpt4 key购买 nike

我有一个 UIViewController,它使用自定义转换呈现,并且根据设计,它仅填充屏幕高度的 90%。

这看起来不错,我从来没有遇到过任何问题。我们将其称为 View A。现在我尝试在此之上呈现一个全屏模态视图,我们将其称为 View B。此外观有效,但当 View B 被关闭时, View A 会重新出现,但已扩展以填充 View B。屏幕的整个边界。

这是我正在使用的演示代码:

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
...
// Presentation
const CGFloat viewHeight = (screenBounds.size.height * 0.9);
const CGRect beginFrame = CGRectMake(0, screenBounds.size.height, screenBounds.size.width, viewHeight);
const CGRect finalFrame = CGRectMake(0, (screenBounds.size.height - viewHeight), screenBounds.size.width, viewHeight);

// Dim
self.dimmedView.alpha = 0.0;
[transitionContext.containerView addSubview:self.dimmedView];
[transitionContext.containerView addConstraints:[NSLayoutConstraint allConstraintsFromViewToSuperview:self.dimmedView inset:UIOffsetZero]];

// Prepare
UIView * const toView = toVC.view;
toView.frame = beginFrame;
[transitionContext.containerView addSubview:toView];

// Animate
[UIView animateWithDuration:kAnimationDuration delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:0.25 options:0 animations:^{
toView.frame = finalFrame;

self.dimmedView.alpha = 0.6;

self.tabBarController.view.layer.cornerRadius = 8.0;
self.tabBarController.view.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
[offshootView removeFromSuperview];
}];
...
}

有人以前见过这个,并且知道如何阻止系统调整 View A 的大小吗?

最佳答案

我认为问题在于您修改了 View Controller Root View 的大小,尽管它是由 View Controller 处理的。 UIViewController 的文档说:

A view controller’s root view is always sized to fit its assigned space.

为什么不将另一个(完全透明) View 作为 subview 添加到放置所有内容的 Root View 中?这样做可以让您将 Root View 保持在 100%,同时在需要时将新 View 的大小更改为 90%。如果我理解正确的话,这将在不触及 Root View 的情况下完成同样的事情。

为此,您应该将 Storyboard属性检查器中的 View Controller 演示属性设置为全屏。如果您想通过代码设置它,请设置 View Controller 的 .modalPresentationStyle = UIModalPresentationOverFullScreen。通过设置此选项,在您呈现 View Controller 后,底层 View Controller 将保留在屏幕上,并在 View 具有透明度的情况下继续可见。

Documentation for UIViewController

Documentation for UIModalPresentationOverFullScreen

关于ios - UIViewController 在模式呈现后更改尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56573738/

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