【问题标题】:Is it possible to add a background Image to a CAShape? (iPhone)是否可以将背景图像添加到 CAShape? (苹果手机)
【发布时间】:2011-04-07 09:20:49
【问题描述】:

我试图以任意方式扭曲图像,例如贝塞尔形状。我使用 CAShapeLayer 创建形状,但似乎将其内容设置为 Image 不起作用。我怎样才能使图像按照该形状变形?有没有可能?

谢谢!

【问题讨论】:

    标签: iphone cashapelayer


    【解决方案1】:

    这是不可能的,但我通过将 CALayer 放在 CAShapeLayer 上成功地做到了。 这是我的代码:

    CALayer *image =[CALayer layer];
    image.frame = CGRectMake(0, 0, 75, 75);
    image.contents = (id) [UIImage imageNamed:@"number-1"].CGImage;    
     [self.layer addSublayer:image];
    
    
    
    UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 75, 75)];
    blueCircleLayer = [CAShapeLayer layer];
    blueCircleLayer.path = circle.CGPath;
    blueCircleLayer.strokeColor = [UIColor blueColor].CGColor;
    blueCircleLayer.fillColor = [UIColor clearColor].CGColor;
    blueCircleLayer.shadowColor =[UIColor blackColor].CGColor;
    blueCircleLayer.shadowOffset = CGSizeMake(0.0f, 5.0f);
    blueCircleLayer.shadowOpacity = 0.7f;
    blueCircleLayer.lineWidth = 7.0;
    
    [self.layer addSublayer:blueCircleLayer];
    

    【讨论】:

    • 在正确的轨道上,从这里扩展并将image的掩码设置为blueCircleLayer
    【解决方案2】:

    目前这是不可能的。如果您认为应该支持此功能,我建议您提交雷达(http://bugreport.apple.com)

    另见:Can a CGImage be added to the contents property of a CAShapeLayer?

    【讨论】:

    • 嗨 casademora,感谢您的回答。那么,以遵循例如贝塞尔路径的形状扭曲图像的最佳方法是什么?我必须转向 openGL ES 和纹理吗?
    • 当我发现该选项不受支持时,我停止了调查。我的猜测是,使用 OpenGL 会给你更多的选择......你可以创建一个形状,并将你的图像映射为纹理,但这就是我对 openGL 的了解...... :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2012-04-09
    • 2011-06-01
    相关资源
    最近更新 更多