简体   繁体   English

CALayer 中的 CGImage 出现倒置

[英]CGImage in CALayer appears upside down

When adding an UIImage to a CALayer it appears upside down.将 UIImage 添加到 CALayer 时,它看起来是颠倒的。 I know it's an issue related to the conversion to a CGImage but i couldn't find any working solution.我知道这是与转换为 CGImage 相关的问题,但我找不到任何可行的解决方案。 all attempt to fix the orientation has failed所有修复方向的尝试都失败了

   `guard let img = UIImage(named: selected)  else {return}
    guard let cg = img.cgImage  else {return}
    CATransaction.begin()
        let faceLayer = arr[indexPath.row]
        let myLayer = CALayer()
        myLayer.frame = faceLayer.bounds
        myLayer.contents = cg
        myLayer.opacity = 1.0
        faceLayer.opacity = 1.0
        myLayer.backgroundColor = UIColor.clear.cgColor
        faceLayer.addSublayer(myLayer)
        pathLayer?.addSublayer(faceLayer)
    CATransaction.commit()`

Eventually i just rotate the UIImage before converting it to CGImgae.最终,我只是在将 UIImage 转换为 CGImgae 之前旋转它。 This cane also be achieved by rotating the layer itself using affineTransform().这也可以通过使用 affineTransform() 旋转图层本身来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM