【发布时间】:2017-01-25 00:03:28
【问题描述】:
在 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 框架中开发了相同的东西,我很难看出区别。
【问题讨论】:
标签: macos cocoa swift3 calayer nsimage