【问题标题】:iOS - Rotating view reveals backgroundiOS - 旋转视图显示背景
【发布时间】:2010-06-16 14:46:38
【问题描述】:

我创建了一个我希望能够旋转的视图。这两个视图是:containerView,它有一个红色的.backgroundColorBackgroundImage 作为子视图。这是我的旋转代码:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  [self adjustViewsForOrientation:toInterfaceOrientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return YES;
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
    backgroundImage.image = [UIImage imageNamed:@"landscape.jpg"];
    backgroundImage.frame = CGRectMake(0, 0, 1024, 704);
    containerView.frame = CGRectMake(0, 0, 1024, 704);
    self.title = @"landscape";
  } else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    backgroundImage.image = [UIImage imageNamed:@"portrait.jpg"];
    backgroundImage.frame = CGRectMake(0, 0, 768, 960);
    containerView.frame = CGRectMake(0, 0, 768, 960);
    self.title = @"portrait";
  }
}

问题是图像旋转,但在视图旋转时显示背景颜色。这个问题有没有很好的解决方案(我知道我可以创建图像以混合成一种颜色并将背景设置为相同的颜色,但这不是我想要的)。

问题的视频可以看这里:http://tinypic.com/r/2quj24g/6

PS 图片来自OmniGroup GitHub repo,仅用于演示。

【问题讨论】:

    标签: iphone ipad ios


    【解决方案1】:

    解决这个问题的方法是将UIView 或UIWindow 的backgroundColor 设置为[UIColor blackColor]。当您旋转 Safari 时,会发生完全相同的事情,只是背景颜色是黑色,就像通常应该的那样。 iPad 上的所有应用程序都是这样旋转的,用户不会注意到任何差异。

    PS- 不要使用willRotateToInterfaceOrientation:duration: 方法,而是使用willAnimateRotationToInterfaceOrientation:duration:

    【讨论】:

      【解决方案2】:

      您可以使图像大于屏幕尺寸。因此,在 iphone 上,将图像设置为 480 x 480。或者在您的情况下,设置为 1024 x 1024。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-15
        • 1970-01-01
        相关资源
        最近更新 更多