2010-07-05 57 views
2

我有一个UIImageView作为我的应用程序的背景图像,它像一个遇险的直升机一样自动旋转。问题是何时自动旋转我的图像的方向会在各处移动,我不喜欢它。由于这是一个简单的纹理,我认为用户宁愿让它保持原位,而不是自动旋转。我的意思是,我希望图像保持全屏,当用户旋转手机时,图像旋转90度,因此图像对于手机而言是静态的,而不是应用程序的其余部分。如何保持自动旋转的图像?

+1

你实际上得到的是工作的解决方案?我不能...(看到接受的答案评论) – 2011-08-16 04:42:30

回答

1

您可以尝试在您的视图控制器中实施willAnimateRotationToInterfaceOrientation:duration:方法,并沿相反方向旋转UIImageView

下面的代码是从我的头顶,我不能保证它会成功:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
    CGFloat angle = M_PI/2; // Figure out the proper angle 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:duration]; 
    imageview.transform = CGAffineTransformMakeRotation(angle); 
    [UIView commitAnimations]; 
} 
+0

这确实有用吗?我在这里尝试:http://stackoverflow.com/questions/7073296/ios-strange-behaviour-rotating-uiimageview-inside-uiview和获得100%失败 – 2011-08-16 04:42:00

0

我建议在图像编辑软件旋转图像和动态加载。这远比做角度来得容易,而且代码更容易阅读。

像这样:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 

     myBackground.image = [UIImage imageNamed:@"bg.jpg"];    

    } else { // landscape view  

     myBackground.image = [UIImage imageNamed:@"bg_landscape.jpg"]; 

    } 
}