iOS 5.1: - [UIColor colorWithPatternImage:]背景颜色绘制纯黑色 [英] iOS 5.1 : -[UIColor colorWithPatternImage:] background color draws solid black

查看:138
本文介绍了iOS 5.1: - [UIColor colorWithPatternImage:]背景颜色绘制纯黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在今天发布的iOS 5.1 GM中测试我的应用程序时,我注意到我的一些视图是绘制纯黑色而不是图案背景颜色。完全相同的代码在之前的iOS版本上运行良好(在4.2 - 5.0.1上测试)。

While testing my application in today's release of iOS 5.1 GM, I noticed that some of my views are drawing solid black rather than their patterned background color. The exact same code works fine on previous iOS releases (tested on 4.2 - 5.0.1).

查看截图:

See screenshots:

还有其他人有过这样的经历吗?是否有解决方法?

Has anybody else experienced this? Is there a workaround?

推荐答案

回答我自己的问题(我花了几天时间来调试这个,所以希望能节省一些人否则一些时间;)):

Answering my own question (it took me a few days to debug this, so hopefully this saves somebody else some time ;) ):

根本原因涉及使用图案化的UIColor(通过 + [UIColor colorWithPatternImage:] )作为具有相同图像的UIImageView上方的UIView的背景颜色。

The root cause involves using an patterned UIColor (via +[UIColor colorWithPatternImage:]) as a background color on a UIView that is above a UIImageView with the same image.

示例:

    UIImageView *imageView = [[UIImageView alloc] initWithImage:anImage];
    [_containerView addSubview:imageView];

    UIColor *patternColor = [UIColor colorWithPatternImage:anImage];
    UIView  *patternView = [[UIView alloc] initWithFrame:frame];
    [patternView setBackgroundColor:patternColor];
    [_containerView addSubview:patternView];

两个视图均为黑色,并且似乎存在缓存问题,其中图像的所有其他用途均已绘制在应用程序暂停/恢复之前黑色。

Both views draw black, and there appears to be a caching issue where all other uses of the image draws black until the application is suspended/resumed.

我向Apple提交了问题#10795514以报告此问题,但看起来它已经变成了5.1。可以通过以下方式减少此问题: http://iccir.com/public/radar/Radar10795514.zip

I filed issue #10795514 with Apple to report this, but it looks like it made it into 5.1. A reduction of this problem is available at: http://iccir.com/public/radar/Radar10795514.zip

我找到的唯一解决方法是展平视图层次结构并在同一视图中两次绘制图案图像。

The only workaround I found was to flatten the view hierarchy and draw the pattern image twice in the same view.

这篇关于iOS 5.1: - [UIColor colorWithPatternImage:]背景颜色绘制纯黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆