简体   繁体   English

UINavigationController-在所有视图中保留背景图像

[英]UINavigationController - Keep Background Image Across All Views

Is there a way to have a background image remain constant across all views in a navigation controller? 有没有办法使导航控制器中的所有视图的背景图像保持恒定? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. 目前,我正在每个视图的viewDidLoad方法中加载相同的背景,但这显示了从一个视图导航到另一个视图时背景图像的移动。 I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. 我宁愿开/关屏幕背景上的“幻灯片”的观点的仅仅是内容,但背景逗留静止。 This is my current background image loading code: 这是我当前的背景图片加载代码:

UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:@"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];

Thanks! 谢谢!

Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. 嗯,也许如果您查看文档 (向下滚动至图2),您将会了解要处理的内容。 Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. 因为您正在为要推入UINavigationController的每个视图控制器设置背景图像,所以将获得该动画。 What you need to do is set the background image into the nav controller itself. 您需要做的是将背景图像设置在导航控制器本身中。

I believe myNavController.view insertSubview:myImageView atIndex:0 should work. 我相信myNavController.view insertSubview:myImageView atIndex:0应该可以工作。 If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. 如果您的图像需要准确地填充在内容视图的后面,则可以根据导航栏和工具栏的坐标和/或高度来设置帧坐标,可以通过导航控制器的属性来访问它们。 If not, just set the frame to the superview's bounds. 如果不是,则将框架设置为超级视图的边界。

Let me know how it goes. 让我知道事情的后续。

Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds. 编辑:哦,请注意,您需要确保每个视图控制器都具有透明背景。

我认为更好的主意是将背景图像放在窗口上,并将所有视图(所有viewcontroller的视图)的背景色设置为清除颜色[UIColor clearColor]

if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. 如果您希望背景图像是静态的,那么只有一种方法,但我不知道这是不可能的,如果我们将图像放在窗口中并使导航控制器透明,那么无论您做什么,它都将保持静态。 because we are not changing window while push or pop. 因为在按下或弹出时我们不会更改窗口。

I am just suggesting try this way i haven't tried like this. 我只是建议以这种方式尝试,而我还没有这样尝试过。

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

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