简体   繁体   English

翻转视图时的UINavigationController背景色

[英]UINavigationController background color while flipping views

Okay, so here it goes. 好的,就这样。 I have a project with a fairly complex interface, including a hierarchical navigator on which when I select a leaf item, I'm presenting either one of two content controllers (because the user can view products which are of two kinds that need their own controller). 我有一个具有相当复杂的界面的项目,其中包括一个分层导航器,当我选择一个叶子项时,我将显示两个内容控制器中的一个(因为用户可以查看需要他们自己的控制器的两种产品) )。 Think of it as a folder navigator, where folder are nested, and there are only two kind of files, each having its own viewer. 可以将其视为文件夹导航器,其中嵌套了文件夹,并且只有两种文件,每种文件都有自己的查看器。 When I select a file, I present a modal controller, either a "docAViewController", either a "docBViewController". 选择文件时,将显示一个模式控制器,即“ docAViewController”或“ docBViewController”。

That's working perfectly. 很好。

My problem is: the docBViewController is a UINavigationController that flips between two UIViewControllers. 我的问题是:docBViewController是一个UINavigationController,它在两个UIViewController之间切换。 (I've inherited that from another developer's architecture and have to cope with it). (我已经从另一个开发人员的体系结构中继承了这一点,必须加以应对)。

When I flip the two view controllers (a viewer and an info pane), the background color is white when I want it to be black. 当我翻转两个视图控制器(一个查看器和一个信息窗格)时,当我希望它是黑色时,背景颜色是白色。 The docBViewController is created by code (no XIB), and I've tried setting its background color by [self.view setBackgroundColor:[UIColor blackColor]] in its viewDidLoad method, it does nothing. docBViewController是由代码创建的(没有XIB),并且我尝试通过其viewDidLoad方法中的[self.view setBackgroundColor:[UIColor blackColor]]设置其背景颜色,但没有执行任何操作。

Anyone knows where/how I can achieve that? 有谁知道我在哪里/如何实现?

How are you flipping the views? 您如何翻转视图? There are a few ways to do it. 有几种方法可以做到这一点。

I've noticed that when using UIView transitionFromView:toView:duration:options:completion that both the view being flipped and the view replacing it must share a parent view of the same size for the animation to work correctly. 我注意到使用UIView transitionFromView:toView:duration:options:completion时,要翻转的视图和替换它的视图必须共享相同大小的父视图,动画才能正常工作。 More to your question, this parent view's background does not appear (if the background is black, you might still see white while the other views flip), but its parent's background will. 更要问的是,该父视图的背景不会出现(如果背景为黑色,则其他视图翻转时您可能仍会看到白色),但其父背景会出现。

So... 所以...

The view you are flipping needs 1.) a parent that will define the area being flipped and 2.) a parent of its parent for a background that doesn't move during the animation. 您要翻转的视图需要1.)一个父级,它将定义要翻转的区域; 2。)它的父级的父级,其背景在动画期间不会移动。

This is what I've observed. 这就是我观察到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM