【问题标题】:CALayer colorWithPatternImage UIImageOrientationCALayer colorWithPatternImage UIImageOrientation
【发布时间】:2012-11-10 18:31:39
【问题描述】:

我已成功使用 colorWithPatternImage 在用于演示背景的 CALayer 中创建背景颜色。但是,图像以颠倒的颜色呈现。我从数小时的阅读帖子和文档中了解到,这是因为屏幕坐标相反。

所以,我尝试了在阅读帖子数小时后发现的这段代码,但它不起作用。

下面使用的 pImage 是之前从 NSURLConnection 加载的。

flippedImage = [UIImage imageWithCGImage:pImage.CGImage scale: 1.0f orientation: UIImageOrientationDownMirrored];

self.backgroundColor = [UIColor colorWithPatternImage:flippedImage].CGColor;

self.anchorPoint = CGPointMake(0.0,0.0);

我应该说我在后台线程中执行此操作。我还尝试了文档中的其他方向,但它们都不适用于我的代码。

谢谢

【问题讨论】:

    标签: iphone ios calayer uiimageorientation


    【解决方案1】:

    翻转图层!?将 geometryFlipped 设置为 YES

    【讨论】:

    • 谢谢,我试试看。
    • 我试过 self.geometryFlipped = YES 和 [self setGeometryFlipped:YES];两者都不起作用。
    • 好的,我发现使用 self.transform = CATransform3DRotate 会向左翻转另一层,但会将层的顶部置于父层的边界之外。有人可以为此提供设置和坐标的链接吗?
    • 您的任务已被编辑,现在对我来说看起来很酷。 UIImage 在制作颜色之前被翻转。那也不行?
    • 抱歉所有回答我自己的问题,但我通过玩 CATransform3DRotate 和 CALayer anchorPoint 找到了解决方案。我认为这可能会对某人有所帮助。这是解决问题的代码 self.backgroundColor = [UIColor colorWithPatternImage:pImage ].CGColor; self.transform = CATransform3DRotate(CATransform3DIdentity, M_PI, 0, 0, 1); self.anchorPoint = CGPointMake(1.0,1.0);
    猜你喜欢
    • 2013-02-11
    • 1970-01-01
    • 2011-04-08
    • 2023-03-04
    • 2011-11-28
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2015-12-26
    相关资源
    最近更新 更多