Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 UIImageView背景图像和旋转帮助_Iphone_Objective C_Ios_Uiimageview_Uiinterfaceorientation - Fatal编程技术网

Iphone UIImageView背景图像和旋转帮助

Iphone UIImageView背景图像和旋转帮助,iphone,objective-c,ios,uiimageview,uiinterfaceorientation,Iphone,Objective C,Ios,Uiimageview,Uiinterfaceorientation,在我的iPad应用程序中,我目前有一个1024x1024像素的背景图像png,并使用以下设置 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image"]]; [self.view addSubview:imgView]; [self.view sendSubviewToBack:imgView]; [imgView release]; 这将添加UIImage

在我的iPad应用程序中,我目前有一个1024x1024像素的背景图像png,并使用以下设置

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image"]];
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];
[imgView release];
这将添加UIImageView精细,视图在横向居中,但在纵向偏离中心

我玩过一些contentMode设置,但运气不好,我要么以肖像为中心,要么以风景为中心,但不能两者兼而有之

有人能帮我在旋转后使UIImageView在纵向和横向上居中吗

提前谢谢
马特

您需要设置
内容模式
和适当的自动调整大小掩码:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image"]];
imgView.frame = self.view.bounds;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imgView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];
[imgView release];

检查
imageView
autoresizingMask
属性。。。真不敢相信我错过了autoresizingMask,我正试图将UIViewAutoresizingFlexibleWidth应用到contentMode。这让我在过去的一天里都快发疯了。在我的应用程序的所有视图后面显示此UIImageView的最佳做法是什么?目前,我已将所有视图背景颜色设置为clearColor,并已将上述代码放入我的视图中,并将显示在导航控制器上。非常感谢omzadd imageview主窗口并使所有控制器透明。但自动调整大小对此不起作用。您需要手动旋转window@rahul你有关于如何手动旋转窗口的代码示例吗?这被认为比我所做的更好吗?因为导航控制器总是可用的,它负责旋转。@马特·普莱斯在谷歌上找到如何设置状态栏的方向。通过旋转状态栏窗口将旋转。感谢7kv7,omz给出了稍微更详细的答案和代码示例,但非常感谢您的回复。自动重设屏幕是关键。@Matt当然。快乐编码:)