Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS背景图像被Navbar压扁_Iphone_Ios_Background_Uinavigationbar_Uitabbar - Fatal编程技术网

Iphone iOS背景图像被Navbar压扁

Iphone iOS背景图像被Navbar压扁,iphone,ios,background,uinavigationbar,uitabbar,Iphone,Ios,Background,Uinavigationbar,Uitabbar,我有一个应用程序正在使用uitabar和UINavigationBar。我正在创建一个包含背景图像的UIImageView,然后将该UIImageView添加到我的self.view子视图中。这会使背景垂直显示为“挤压”。背景图像直到导航栏底部才开始,然后在选项卡栏后面向下运行 下面是我用来添加背景的代码: UIImageView* backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"backgrou

我有一个应用程序正在使用
uitabar
UINavigationBar
。我正在创建一个包含背景图像的
UIImageView
,然后将该
UIImageView
添加到我的
self.view
子视图中。这会使背景垂直显示为“挤压”。背景图像直到导航栏底部才开始,然后在选项卡栏后面向下运行

下面是我用来添加背景的代码:

UIImageView* backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    [backgroundView setFrame:CGRectMake(0, 0, 320, 480)];
    [self.view addSubview:backgroundView];

任何关于如何保持背景实际大小的想法都将不胜感激。

首先,如果iPhone/iPod 5上没有
UINavigationBar
,您将无法使用480个高度点。您应该使用
self.view.frame.size.height
获得实际尺寸。实际上,您应该将框架设置为视图的边界

[backgroundView setFrame:self.view.bounds];
其次,您应该设置
UIImageView
contentMode
属性

[backgroundView setContentMode:UIViewContentModeScaleAspectFill]; //Set UIViewContentModeScaleAspectFit if you want to show the full image with the potential of a letterbox

这应该能解决你的问题。

我不太清楚你在问什么。是的,属于选项卡栏控制器或导航控制器的任何视图都将调整大小以适应剩余的屏幕空间,但在考虑其他UI元素占用的空间后,您确切知道图像视图将剩下多少空间:

状态栏:320 x 20(纵向),480 x 20(横向)导航栏:320 x 44(纵向),480 x 34(横向)选项卡栏:320 x 49(纵向),480 x 49(横向)

因此,基本上,您的图像视图有以下可用空间:

肖像:320 x 367土地空间:480 x 217


设计Default.png时要考虑这些尺寸。老实说,将第一个屏幕与Default.png匹配的最简单方法是简单地拍摄iOS模拟器的屏幕截图。

这是在iPhone 5情节提要上创建的吗?容器视图是否具有自动调整子视图大小的属性?这可能就是问题所在。。。