UINavigationController - 在所有视图中保留背景图像 [英] UINavigationController - Keep Background Image Across All Views

查看:20
本文介绍了UINavigationController - 在所有视图中保留背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让背景图像在导航控制器的所有视图中保持不变?目前我在每个视图的 viewDidLoad 方法中加载相同的背景,但这显示了在视图之间导航时背景图像移动.我宁愿只是背景幻灯片"开/关屏幕的视图 infront 的内容,但背景保持静止.这是我当前的背景图片加载代码:

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. 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];

谢谢!

推荐答案

嗯,也许你看看 文档(向下滚动到图 2)您将了解您正在处理的内容.因为您正在为每个被推送到 UINavigationController 的视图控制器设置背景图像,所以您将获得该动画.您需要做的是将背景图像设置到导航控制器本身.

Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. 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. What you need to do is set the background image into the nav controller itself.

我相信 myNavController.view insertSubview:myImageView atIndex:0 应该可以工作.如果您的图像需要准确地填充在内容视图后面,您可以根据导航栏和工具栏的坐标和/或高度设置框架坐标,可以通过导航控制器的属性访问.如果没有,只需将框架设置为超级视图的边界即可.

I believe myNavController.view insertSubview:myImageView atIndex:0 should work. 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.

告诉我进展如何.

哦,请注意,您需要确保每个视图控制器都有透明背景.

Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.

这篇关于UINavigationController - 在所有视图中保留背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆