每次实现基于Metal的ImageView时,我都会遇到同样的问题。
let targetTexture = currentDrawable?.texture else{ return }
类型“MTLDrawable”的值没有成员“texture”
似乎苹果公司更改了一些 Metal API
这是我正在尝试使用的完整函数:
func renderImage()
{
guard let
image = image,
let targetTexture = currentDrawable?.texture else{return}
let commandBuffer = commandQueue.makeCommandBuffer()
let bounds = CGRect(origin: CGPoint.zero, size: drawableSize)
let originX = image.extent.origin.x
let originY = image.extent.origin.y
let scaleX = drawableSize.width / image.extent.width
let scaleY = drawableSize.height / image.extent.height
let scale = min(scaleX, scaleY)
let scaledImage = image
.applying(CGAffineTransform(translationX: -originX, y: -originY))
.applying(CGAffineTransform(scaleX: scale, y: scale))
ciContext.render(scaledImage,
to: targetTexture,
commandBuffer: commandBuffer,
bounds: bounds,
colorSpace: colorSpace)
commandBuffer.present(currentDrawable!)
commandBuffer.commit()
}
currentDrawable
变量的声明和赋值。根据错误提示,它的类型是MTLDrawable
,实际上并没有texture
属性。我想你可能在想CAMetalDrawable
,它有这个属性。 - Ken ThomasesMTKView
的子类吗? - Ken Thomases