使用cameraoverlay时,imagepicker不会显示图像

时间:2017-01-11 22:30:11

标签: ios swift

我想自定义相机场景,所以我使用自定义叠加。它隐藏了默认的相机按钮并显示其他按钮。当我拍照时,我想看到静态图像,但我只看到了相机。我尝试在customView中放置一个图像视图,但相机仍然在后台运行。

  func cameraProperty()
    {

    DispatchQueue.main.async(execute: {
        //let imagePicker = UIImagePickerController()
        self.picker.navigationBar.isTranslucent = false
        self.picker.navigationBar.barTintColor = .blue // Background color
        self.picker.navigationBar.tintColor = .white // Cancel button ~ any UITabBarButton items
        self.picker.navigationBar.titleTextAttributes = [
            NSForegroundColorAttributeName : UIColor.white
        ] //

        self.picker.sourceType = UIImagePickerControllerSourceType.camera
        self.picker.cameraDevice = .front
        self.picker.delegate = self
        self.picker.showsCameraControls = false
        self.picker.modalPresentationStyle = .fullScreen

        //customView stuff
        let customViewController = CustomOverlayViewController(
            nibName:"CustomOverlayViewController",
            bundle: nil
        )
        let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
        customView.frame = self.picker.view.frame
        customView.delegate = self


        customView.skipBtn.setTitle("SKIP", for: .normal)
        customView.createSongBtn.isHidden = true
        customView.takePhotoBtn.isHidden = false
        customView.curImg.isHidden = true

        //CGSize screenSize = [[UIScreen mainScreen] bounds].size;

        let screenSize:CGSize = UIScreen.main.bounds.size

        let ratio:CGFloat = 4.0 / 3.0
        let cameraHeight:CGFloat = screenSize.width * ratio
        let scale:CGFloat = screenSize.height / cameraHeight

        //need to test it for different phone sizes
        self.picker.cameraViewTransform = CGAffineTransform(translationX: 0, y: (screenSize.height - cameraHeight) / 2.0)
        self.picker.cameraViewTransform = self.picker.cameraViewTransform.scaledBy(x: scale, y: scale)


        self.picker.cameraOverlayView = customView
        self.picker.allowsEditing = false
        })

    }


   func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
        picker.dismiss(animated: true, completion: nil)
    }


    //MARK: Custom View Delegates
    func didCancel(overlayView:CustomOverlayView) {

    DispatchQueue.main.async(execute: {
        if overlayView.skipBtn.titleLabel?.text == "SKIP"
        {
            self.picker.dismiss(animated: true,completion: nil)
            print("dismissed!!")
        }
        else
        {
            overlayView.skipBtn.setTitle("SKIP", for: .normal)
            overlayView.createSongBtn.isHidden = true
//            overlayView.curImg.isHidden = true
            overlayView.takePhotoBtn.isHidden = false
            print("Reset camera")
        }
    })

    }
    func didShoot(overlayView:CustomOverlayView) {
    DispatchQueue.main.async(execute: {
        self.picker.takePicture()
        overlayView.skipBtn.setTitle("Try Again", for: .normal)
//        overlayView.sendSubview(toBack: overlayView.curImg)
        overlayView.createSongBtn.isHidden = false
        overlayView.takePhotoBtn.isHidden = true
    })
        print("Shot Photo")
    }

如何使用图像(也是自定义视图)和“使用照片”选项显示视图。

0 个答案:

没有答案