【发布时间】:2013-11-19 18:29:24
【问题描述】:
我有一个 UIImageView 用于显示我的应用程序的背景图像,因此占据了整个屏幕,根据屏幕尺寸/设备(480 点或 568 点)和方向,图像在 4 个图像中的 1 个之间更改.
我一直在寻找是否有一种方法可以动画显示方向之间的图像切换,因为当前旋转设备时切换非常“苛刻”并简要显示后面的空白区域。
我从 google/here 发现的大部分内容是人们询问如何在 uiimageviews 之间进行动画更改,这不是我想要的,我只是更改代码中单个 uiimageview 中显示的图像,如下面的 sn-p:
- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
if (IS_WIDESCREEN && UIInterfaceOrientationIsPortrait(orientation)) {
self.backgroundImage.image = [UIImage imageNamed:@"iPhone5backgroundPortrait.png"];
_backgroundImage.frame = CGRectMake(0, 0, 320, 568);
} if (IS_NOT_WIDESCREEN && UIInterfaceOrientationIsPortrait(orientation)) {
self.backgroundImage.image = [UIImage imageNamed:@"iPhone4backgroundPortrait.png"];
_backgroundImage.frame = CGRectMake(0, 0, 320, 480);
} if (IS_WIDESCREEN && UIInterfaceOrientationIsLandscape(orientation)) {
self.backgroundImage.image = [UIImage imageNamed:@"iPhone5backgroundLandscape.png"];
_backgroundImage.frame = CGRectMake(0, 0, 568, 320);
} else if (IS_NOT_WIDESCREEN && UIInterfaceOrientationIsLandscape(orientation)) {
self.backgroundImage.image = [UIImage imageNamed:@"iPhone4backgroundLandscape.png"];
_backgroundImage.frame = CGRectMake(0, 0, 480, 320);
我尝试了 [animateImageNamed: duration:] 方法,但是当设备旋转时背景消失了!
谢谢
【问题讨论】:
标签: ios objective-c uiimageview orientation