Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Vladimir Zhelnov - neatek.pw - Web/iOS dev
- //
- // Class_CameraView.swift
- // iconbaseApp
- //
- // Created by Vladimir on 04.11.16.
- // Copyright © 2016 Vladimir Zhelnov. All rights reserved.
- //
- import UIKit
- //import Haneke
- //import Kingfisher
- import AVFoundation
- @available(iOS 10.0, *)
- class Class_CameraView: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
- @IBOutlet weak var cameraView: UIView!
- var captureSession = AVCaptureSession();
- var sessionOutput = AVCapturePhotoOutput();
- var sessionOutputSetting = AVCapturePhotoSettings(format: [AVVideoCodecKey:AVVideoCodecJPEG]);
- var previewLayer = AVCaptureVideoPreviewLayer();
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
- }
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- previewLayer.frame = cameraView.bounds
- }
- 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);
- captureSession.startRunning()
- print("Start Running")
- } else {
- print("Cant add output")
- }
- } else {
- print("Cant add input")
- }
- }
- catch{
- print("exception!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement