【问题标题】:Visual artifacts on UIView rotation with tiled background image带有平铺背景图像的 UIView 旋转上的视觉伪影
【发布时间】:2010-10-05 23:18:49
【问题描述】:

我有一个带有标准 UIViewController/UIView 设置的 iPad 应用程序 - 允许所有旋转。 UIView 绘制一些平铺图像作为背景(平铺为 256*256 像素):

- (void)drawRect:(CGRect)rect
{
    [[UIImage imageNamed: @"Background.png"] drawAsPatternInRect: rect];
}

当我转动我的 iPad 时,我可以看到在旋转过程中,原始方向的图像图案被 缩放 以适应新的方向。然后 - 动画完成后 - 视图重绘其背景图案,最终配置未缩放。从缩放模式切换到非缩放模式看起来有点难看。

有没有办法绕过(或隐藏)背景图案的这种拉伸?

【问题讨论】:

    标签: uiview background rotation design-patterns tile


    【解决方案1】:

    为什么不使用图案图像作为背景“颜色”?这会自动生成平铺图案并避免使用 drawRect() 的任何特技。例如:

    UIImage *backgroundTile = [UIImage imageNamed: @"Background.png"];
    UIColor *backgroundPattern = [[UIColor alloc] initWithPatternImage:backgroundTile];
    [myView setBackgroundColor:backgroundPattern];
    [backgroundPattern release];
    

    【讨论】:

    • 我会尝试您的解决方案,但我自己也想出了一个解决方案:当我在 viewController 的 'willRotateToInterfaceOrientation:duration' 方法中使用 'setNeedsDisplay' 将视图标记为重绘时,视图将在之后立即重绘转动 iPad,但在旋转动画完成之前。这意味着,背景图像在动画开始时被拉伸,并在动画期间平滑地展开。这对人眼来说不再明显了。
    【解决方案2】:

    简单来说,

    [myView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      相关资源
      最近更新 更多