Tôi đã tạo ra một phong tục AVFoundation camera và nạp vào xem nhau như subview với @IBDesignable, sau khi hình ảnh được lấy tôi muốn gán nó vào UIImageView
, Nhưng khi nhấn nút, chế độ xem máy ảnh tùy chỉnh (UIView
) bị lỗi và di chuyển lên màn hình, thay vì gán nó vào UIImageView
, Điều này xảy ra khi chế độ xem máy ảnh tùy chỉnh ở đầu, sau đó khi tôi tải máy ảnh tùy chỉnh xem lại, nó sẽ gán hình ảnh cho UIImageView
.subview trong Main Xem sụp đổ Khi gán hình ảnh từ AVFoundation để UIImageView
Capture phương pháp hình ảnh:
@IBAction func captureImage(sender: AnyObject) {
if let stillOutput = self.captureImageOutput {
// we do this on another thread so that we don't hang the UI
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
//find the video connection
var videoConnection : AVCaptureConnection?
for connecton in stillOutput.connections {
//find a matching input port
for port in connecton.inputPorts!{
if port.mediaType == AVMediaTypeVideo {
videoConnection = connecton as? AVCaptureConnection
break //for port
}
}
if videoConnection != nil {
break// for connections
}
}
if videoConnection != nil {
stillOutput.captureStillImageAsynchronouslyFromConnection(videoConnection){
(imageSampleBuffer : CMSampleBuffer!, _) in
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer)
let pickedImage: UIImage = UIImage(data: imageData, scale: 1.0)!
dispatch_async(dispatch_get_main_queue(), {
self.capturePhoto.image = pickedImage
})
}
}
}
}
}
Tôi cũng đã thử các dispatch_sync
và không có gì tải trong UIImageView, nhưng màn hình không sụp đổ.
dispatch_sync(dispatch_get_main_queue(), {
self.capturePhoto.image = pickedImage
})
bạn gặp phải loại vụ tai nạn nào? là có một backtrace cho thấy những gì dòng mã nguồn của bạn đang gây ra vụ tai nạn? –
Tôi không nhận được bất kỳ lỗi nào. @MichaelDautermann – Xrait
Giao diện người dùng chỉ cần treo – Xrait