【发布时间】:2011-07-30 04:19:41
【问题描述】:
iOS4.2 当我的应用程序启动时,我会显示一个在我的 web 视图加载之前可见的图像。在 webview 加载后,该图像被设置为隐藏。如何执行以下操作: 如果是纵向,则显示 DefaultPortrait.png 如果是横向则显示 DefaultLandscape.png?
如果设备是纵向的,则显示
self.view.backgroundColor = [UIColor blackColor];
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
或
如果设备是横向的,则显示
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 480f, 320.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2L.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
【问题讨论】:
-
试试我的方法。将 viewDidRotateMethod 放入您的代码中。每当设备旋转时都会调用此函数..
标签: iphone uiimageview ios-4.2 uiinterfaceorientation uideviceorientation