Ios 金属';纹理';找不到

Ios 金属';纹理';找不到,ios,core-image,metal,Ios,Core Image,Metal,对于基于金属的ImageView的每个实现,我都面临着同样的问题 let targetTexture = currentDrawable?.texture else{ return } “MTLDrawable”类型的值没有成员“纹理” 似乎苹果已经改变了一些金属api 以下是我尝试使用的全部功能: func renderImage() { guard let image = image, let targetTexture = currentDrawa

对于基于金属的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不适用于模拟器,但如果您只想让构建通过并集中在应用程序的其他区域,您可以尝试执行类似的操作: 对于那些仍然希望在模拟器上运行的人,至少有一个变通方法可以让它运行和编译(虽然没有金属功能)


显示
currentDrawable
变量的声明和赋值。根据错误,它的类型是
MTLDrawable
,实际上没有
纹理
属性。我想你是在想
CAMetalDrawable
,确实如此。@Kenthomass但在每个实现中,金属套件视图都是以这种方式完成的,并且没有办法从MTLDrawable调用CAMetalDrawable。你是否实现了
MTKView
的子类?它成功了,谢谢。但为什么它会变得如此愚蠢,这是苹果的问题