【问题标题】:How to keep image from autorotating?如何防止图像自动旋转?
【发布时间】:2010-07-05 22:17:17
【问题描述】:

我有一个 UIImageView 作为我的应用程序的背景图像,它就像遇险的直升机一样自动旋转。问题是当方向自动旋转时,我的图像到处移动,我不喜欢它。由于它是一个简单的纹理,我认为用户更愿意让它保持原位,而不是自动旋转。我的意思是我希望图像保持全屏显示,当用户旋转手机时,图像只是旋转了 90 度,因此看起来图像在手机上是静态的,而不是应用程序的其余部分。

【问题讨论】:

  • 您真的找到了有效的解决方案吗?我不能...(请参阅已接受答案的评论)

标签: iphone objective-c fixed autorotate image-rotation


【解决方案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];
}

【讨论】:

【解决方案2】:

我建议在图像编辑软件中旋转您的图像并动态加载它。这比处理角度要容易得多(而且代码更容易阅读)。

像这样:

- (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"];

    }
}

【讨论】:

    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    相关资源
    最近更新 更多