Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Cocoa CALayer不显示NSImage_Macos_Cocoa_Swift3_Calayer_Nsimage - Fatal编程技术网

Macos Cocoa CALayer不显示NSImage

Macos Cocoa CALayer不显示NSImage,macos,cocoa,swift3,calayer,nsimage,Macos,Cocoa,Swift3,Calayer,Nsimage,在CALayer中显示NSImage时出现问题 init(image: NSImage) {      self.image = image      super.init(frame: .zero) } required init(coder aDecoder: NSCoder) {      fatalError("init(coder:) has not been implemented") } override func viewWillDraw() { supe

在CALayer中显示NSImage时出现问题

 init(image: NSImage) {
     self.image = image
     super.init(frame: .zero)
 }

 required init(coder aDecoder: NSCoder) {
     fatalError("init(coder:) has not been implemented")
 }

 override func viewWillDraw() {
     super.viewWillDraw()
     animationLayer.contentsGravity = kCAGravityResizeAspect
     animationLayer.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
     animationLayer.contents = image.cgImage
     animationLayer.masksToBounds = true
     animationLayer.backgroundColor = NSColor.blue.cgColor

     wantsLayer = true
     layer?.addSublayer(animationLayer)
 }
backgroundColor
设置为蓝色的CALayer渲染效果良好,但
NSImage
渲染效果不佳。
NSImage
确认包含所需图像,并在初始化类时设置


在iOS框架内开发了相同的功能,我正在努力寻找差异。

与iOS不同,macOS中
CALayer
image属性考虑的是
NSImage
而不是它的
CGImage
表示

animationLayer.contents = image

与iOS不同,macOS中
CALayer
image
属性考虑的是
NSImage
而不是它的
CGImage
表示

animationLayer.contents = image

删除了我的最后一条评论,因为它确实有效;)“谢谢”删除了我的最后一条评论,因为它确实有效;)谢谢