Macos Cocoa CALayer不显示NSImage
在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
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
删除了我的最后一条评论,因为它确实有效;)“谢谢”删除了我的最后一条评论,因为它确实有效;)谢谢