2011-11-04 130 views
0

我想“锁定”我的背景图像(一个UIImageView),使其看起来不像我旋转设备时被裁剪。它在横向视图中看起来是正确的,但不跟随旋转。旋转设备时如何锁定背景图像?

我试着使用setAutoresizingMask来伸展它,但结果看起来很可怕。我用UIImageView的transform属性弄了一下,但没有使它看起来正确。

任何指针,将不胜感激。我甚至不确定我是否在正确的轨道上。

回答

0

OK,我设法使它工作使用下面的代码:

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
    ... 
     UIColor *color = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
     self.background.backgroundColor = color; 
     [color release]; 
    ... 
    } 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 
    float angle = (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) ? M_PI_2 : 0.0;  
    self.background.transform = CGAffineTransformMakeRotation(angle); 
} 

记住,后台〜ipad.png为1024x768,也就是景观为默认值。如果你的图像是肖像,你需要在条件情况下检查横向而不是纵向。

2

您可以为纵向/横向取向设置不同的图像,并在willRotate回调中使用UIView动画在两者之间切换。我试了一下,结果很顺利。

+0

谢谢,做你的建议听起来是合理的,但我不能让它工作。然而,我设法让旋转工作。 – MdaG