本文介绍了iOS 暗淡背景 查看全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题应该很简单,但我找不到解决方案.

My question should be simple but I couldn't find solution.

我正在显示模态 VC,我想添加暗淡的背景视图.

I am displaying modal VC and I want to append dim background view.

Modal VC 作为子 VC 添加到父 VC.父 VC 放置在 Navigation Controller 的顶部 (topViewController)

Modal VC is added as a child to the parent VC. Parent VC is placed at top of Navigation Controller (topViewController)

Dim 视图被添加到 UIScreen.windows.first! 窗口.但是昏暗的视图并没有填满整个屏幕.我确实使用 CGPointZero 为它设置了框架,我尝试了负 y 值它没有帮助.它看起来像这样.我还添加了一组自动布局约束,设置为 false/true translatesAutoresizingMaskIntoConstraints 属性,更改了 clipToBounds.

Dim view is added to the UIScreen.windows.first! window. But the dim view doesn't fill the whole screen. I do set frame for it with CGPointZero for origin, I tried negative y value it didn't help. It just look like this.Also I added set of auto layout constraints, set to false/true translatesAutoresizingMaskIntoConstraints property, changed clipToBounds.

没什么用,昏暗的视图不会覆盖整个屏幕.

Nothing helps, the dim view doesn't cover entire screen.

我可以全屏显示dim view,如果我不添加modal VC作为孩子,即我直接利用modal VC的视图,并将其添加到窗口.它看起来不错,但还有另一个错误.这就是为什么我要添加模态 VC 作为子 VC.如何强制昏暗视图显示整个屏幕.

I can display the dim view in full screen, if I don't add modal VC as a child, i.e. I directly utilize modal VC's view, and add it to the window. It looks fine, but there is another bug. That's why I am adding modal VC, as a child VC.How to force dim view display the whole screen.

在应用程序中可能同时显示多个模态 VC,这就是为什么 seques(即 VC 的呈现)不是最佳选择的原因.

In the app there might be several modal VC displayed simultaneously, that's why seques, (i.e presentation of VCs) is not the best choice.

附:这是错误的描述:

.如果将模态VC(放置在Nav.Controller中的UITableVC)的视图直接添加到窗口中,视图在从BG返回后显示移位的表格,即在BG中并开始从BG显示模态VC的情况下,之后切换回前台,表格标题的一部分(问题显示部分)向上移动并且模态VC的导航栏被展开,即它们相交,表格的标题没有完全显示.我无法解决这个问题.

. In case of adding modal VC (UITableVC placed into Nav. Controller)'s view directly to the window , view displays shifted table, after returning back from BG, i.e. in case of being in BG and starting to display modal VC from BG, after that switching back to Foreground, part of table's header (Question is revealed part) is shifted up and modal VC's navigation bar is expanded, i.e. they intersect, header of the table isn't display completely. I couldn't fix that.

推荐答案

把你的视图放在导航控制器的视图下:

Put your view under navigation controller's view:

UIView *dimView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
dimView.backgroundColor = [UIColor colorWithWhite:.4f alpha:.5f];
[self.navigationController.view addSubview:dimView];
[self.navigationController.view bringSubviewToFront:dimView];

这篇关于iOS 暗淡背景 查看全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:39