Tôi đang theo dõi video này để thực hiện chế độ xem máy ảnh tùy chỉnh. https://www.youtube.com/watch?v=w0O3ZGUS3pkSwift 3 - AVCapture xem máy ảnh tùy chỉnh
tuy nhiên do iOS 10 và nhanh chóng 3 thay đổi nhiều điều không phù hợp nữa
sau đây là đoạn code tôi đã nhận ra sau khi thay đổi chức năng phản đối đến mới ones..however không có lỗi, nhưng cũng không nhìn thấy một bản xem trước trên UIView
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCapturePhotoCaptureDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var cameraView: UIView!
var captureSession = AVCaptureSession();
var sessionOutput = AVCapturePhotoOutput();
var sessionOutputSetting = AVCapturePhotoSettings(format: [AVVideoCodecKey:AVVideoCodecJPEG]);
var previewLayer = AVCaptureVideoPreviewLayer();
override func viewWillAppear(_ animated: Bool) {
let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.unspecified)
for device in (deviceDiscoverySession?.devices)! {
if(device.position == AVCaptureDevicePosition.front){
do{
let input = try AVCaptureDeviceInput(device: device)
if(captureSession.canAddInput(input)){
captureSession.addInput(input);
if(captureSession.canAddOutput(sessionOutput)){
captureSession.addOutput(sessionOutput);
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession);
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.portrait;
cameraView.layer.addSublayer(previewLayer);
}
}
}
catch{
print("exception!");
}
}
}
}
Nó chỉ nên chạy một lần bất kể mặc dù? –
Có lẽ, nhưng nó làm tôi lo lắng –
Ví dụ, không có hai máy quay mặt sau trên iPhone 7+? Nó không chắc, nhưng bạn có thể nhận được một bất ngờ khó chịu về phần cứng trong tương lai ... –