2017-01-29 14 views
5

Với mỗi Thực hiện kim loại dựa ImageView tôi đang phải đối mặt với cùng một vấn đềkim loại 'kết cấu' không tìm thấy

let targetTexture = currentDrawable?.texture else{ return } 

Giá trị của loại 'MTLDrawable' không có thành viên 'kết cấu'

Có vẻ như táo đã thay đổi một số kim loại api

đây là chức năng đầy đủ Tôi đang dùng thử:

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() 
} 
+0

Hiển thị khai báo và gán biến 'currentDrawable' của bạn. Theo lỗi, đó là loại 'MTLDrawable' mà không, trên thực tế, có một thuộc tính' texture'. Tôi tưởng tượng bạn đang nghĩ đến 'CAMetalDrawable' –

+0

@KenThomases nhưng trong mọi triển khai Chế độ xem bộ kim loại được thực hiện theo cách này và không có cách nào để gọi CAMetalDrawable từ MTLDrawable –

+0

Bạn đang triển khai lớp con của 'MTKView'? –

Trả lời

8

Tôi gặp sự cố tương tự sau khi thực hiện cập nhật hệ thống và xcode. Hóa ra trong quá trình cập nhật, xcode đã chuyển mục tiêu xây dựng thành trình mô phỏng. Sau khi tôi chuyển mục tiêu trở lại thiết bị, tất cả được biên dịch lại.

+3

Nó hoạt động, cảm ơn bạn. Nhưng tại sao nó được làm như vậy freaking stupid đó là một câu hỏi cho Apple –

Các vấn đề liên quan