【发布时间】:2014-09-08 06:26:02
【问题描述】:
我正在尝试将图像作为 ipad 应用程序中 viewcontroller 的背景。我使用
进行设置UIImage *background = [UIImage imageNamed: @"Pilot@2x~ipad.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: background];
imageView.frame = self.view.bounds;
[self.view addSubview: imageView];
[self.view sendSubviewToBack:imageView];
这适用于纵向模式,但是当我将其旋转到横向模式时,会出现图片无法填充的空白区域。我基于其他类似帖子的想法是创建一张新图片,当旋转获取更改时调用它,我尝试了这个
{ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
UIImage *background = [UIImage imageNamed: @"Pilot@2x~ipad.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: background];
imageView.frame = self.view.bounds;
[self.view addSubview: imageView];
[self.view sendSubviewToBack:imageView];
} else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
UIImage *background = [UIImage imageNamed: @"PilotLandscape@2x~ipad.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: background];
imageView.frame = self.view.bounds;
[self.view addSubview: imageView];
[self.view sendSubviewToBack:imageView];
}}
这导致了同样的事情。任何有关如何解决此问题的想法都将不胜感激!
【问题讨论】:
-
当你将设备横向旋转到纵向或纵向到横向时
-
当您将设备从横向旋转到纵向或从纵向旋转到横向时调用? if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){ }else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) {}
-
您的应用中是否自动布局?
-
在您的项目中添加两个不同大小的图像。 1.对于纵向视图-768X1024(retina-1536X2048),2.对于横向视图-1024X768(retina-2048X1536)。现在,在旋转屏幕时更改背景图像(对于纵向图像 No.1 和对于横向图像 No.2)。
标签: ios objective-c ipad uiimageview uiinterfaceorientation