iOS 4.2 如何在方向改变时显示不同的图像?
iOS4.2 当我的应用程序启动时,我会显示一个可见的图像,直到我的 webview 加载为止。 Web 视图加载后,该图像将设置为隐藏。如何执行以下操作: 如果是纵向,则显示 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];
iOS4.2 When my app launches I display an image that is visible until my webview loads. After the webview loads that image is set to hidden. How do I do the following: If portrait, then display DefaultPortrait.png if Landscape the display DefaultLandscape.png?
if Device is Portrait then display
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];
OR
if Device is landscape then display
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
didRotateFromInterfaceOrientation
来实现您的代码。现在,当方向从纵向更改时,实现您想要在设备处于横向模式时显示的代码,反之亦然。希望它能解决您的问题。You can use the
didRotateFromInterfaceOrientation
to implement your code. Now here when the orientation will be changed from portrait implement the code u wanna display when the device is in landscape mode and vice versa. Hope it solves your problem.您可以在开始时使用它来获取当前方向:
然后使用它:
You can use this at the beginning to get your current orientation:
and then use this:
如果您想在两种模式下显示相同的图像,那么首先在应用程序委托文件中声明一个布尔类型变量,并在应用程序委托 .m 文件中定义。如果是纵向模式,则该变量为 true;如果是横向模式,则该变量为 false。现在在
}
If you want to display same image in both mode then first u declare a Boolean type variable in app delegate file and define in app delegate .m file. IF portrait mode the variable true and when landscape then false. Now In
}