随着每个基于Metal的ImageView的实现,我都面临同样的问题
let targetTexture = currentDrawable?.texture else{ return }
“MTLDrawable”类型的值没有成员“纹理”
好像苹果改变了一些金属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()
}
执行系统和xcode更新后,我遇到了同样的问题。在更新过程中,xcode将构建目标切换到模拟器。一旦我将目标切换回设备,它就会再次编译。
Metal不适用于模拟器,但是如果你只是希望构建通过并专注于应用程序的其他区域,你可以尝试做类似的事情:对于那些仍然想在模拟器上运行的人,有一个解决方法至少让它运行和编译(尽管没有金属功能)