     
     // 调整焦距
     @objc func adjustCameraFocus(_ pan: UIPanGestureRecognizer) {
-        let convertRect = self.bottomView.convert(self.largeCircleView.frame, to: self.view)
-        let point = pan.location(in: self.view)
+        let convertRect = bottomView.convert(largeCircleView.frame, to: view)
+        let point = pan.location(in: view)
         
         if pan.state == .began {
-            if !convertRect.contains(point) {
-                return
-            }
-            self.dragStart = true
-            self.startRecord()
+            dragStart = true
+            startRecord()
         } else if pan.state == .changed {
-            guard self.dragStart else {
-                return
-            }
-            let maxZoomFactor = self.getMaxZoomFactor()
+            guard dragStart else {
+                return
+            }
+            let maxZoomFactor = getMaxZoomFactor()
             var zoomFactor = (convertRect.midY - point.y) / convertRect.midY * maxZoomFactor
             zoomFactor = max(1, min(zoomFactor, maxZoomFactor))
-            self.setVideoZoomFactor(zoomFactor)
+            setVideoZoomFactor(zoomFactor)
         } else if pan.state == .cancelled || pan.state == .ended {
-            guard self.dragStart else {
-                return
-            }
-            self.dragStart = false
-            self.finishRecord()
+            guard dragStart else {
+                return
+            }
+            dragStart = false
+            finishRecord()
         }
     }
     

    }
    
    func setupUI() {
        self.view.backgroundColor = .black
        
        self.takedImageView.backgroundColor = .black
        self.takedImageView.isHidden = true
        self.takedImageView.contentMode = .scaleAspectFit
        self.view.addSubview(self.takedImageView)
        
        self.focusCursorView.contentMode = .scaleAspectFit
        self.focusCursorView.clipsToBounds = true
        self.focusCursorView.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
        self.focusCursorView.alpha = 0
        self.view.addSubview(self.focusCursorView)
        
        self.tipsLabel.font = getFont(14)
        self.tipsLabel.textColor = .white
        self.tipsLabel.textAlignment = .center
        self.tipsLabel.numberOfLines = 2
        self.tipsLabel.lineBreakMode = .byWordWrapping
        self.tipsLabel.alpha = 0
        if ZLPhotoConfiguration.default().allowTakePhoto, ZLPhotoConfiguration.default().allowRecordVideo {
            self.tipsLabel.text = localLanguageTextValue(.customCameraTips)
        } else if ZLPhotoConfiguration.default().allowTakePhoto {
            self.tipsLabel.text = localLanguageTextValue(.customCameraTakePhotoTips)
        } else if ZLPhotoConfiguration.default().allowRecordVideo {
            self.tipsLabel.text = localLanguageTextValue(.customCameraRecordVideoTips)
        }
        
        self.view.addSubview(self.tipsLabel)
        self.view.addSubview(self.bottomView)
        
        self.dismissBtn.setImage(getImage("zl_arrow_down"), for: .normal)
        self.dismissBtn.addTarget(self, action: #selector(dismissBtnClick), for: .touchUpInside)
        self.dismissBtn.adjustsImageWhenHighlighted = false
        self.dismissBtn.zl_enlargeValidTouchArea(inset: 30)
        self.bottomView.addSubview(self.dismissBtn)
        
        self.largeCircleView.layer.masksToBounds = true
        self.largeCircleView.layer.cornerRadius = ZLCustomCamera.Layout.largeCircleRadius / 2
        self.bottomView.addSubview(self.largeCircleView)
        
        self.smallCircleView.layer.masksToBounds = true
        self.smallCircleView.layer.cornerRadius = ZLCustomCamera.Layout.smallCircleRadius / 2
        self.smallCircleView.isUserInteractionEnabled = false
        self.smallCircleView.backgroundColor = .white
        self.bottomView.addSubview(self.smallCircleView)
        
        let animateLayerRadius = ZLCustomCamera.Layout.largeCircleRadius
        let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: animateLayerRadius, height: animateLayerRadius), cornerRadius: animateLayerRadius/2)
        self.animateLayer.path = path.cgPath
        self.animateLayer.strokeColor = UIColor.cameraRecodeProgressColor.cgColor
        self.animateLayer.fillColor = UIColor.clear.cgColor
        self.animateLayer.lineWidth = 8
        
        var takePictureTap: UITapGestureRecognizer?
        if ZLPhotoConfiguration.default().allowTakePhoto {
            takePictureTap = UITapGestureRecognizer(target: self, action: #selector(takePicture))
            self.largeCircleView.addGestureRecognizer(takePictureTap!)
        }
        if ZLPhotoConfiguration.default().allowRecordVideo {
            let recordLongPress = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
            recordLongPress.minimumPressDuration = 0.3
            recordLongPress.delegate = self
            self.largeCircleView.addGestureRecognizer(recordLongPress)
            takePictureTap?.require(toFail: recordLongPress)
        }
        
        self.retakeBtn.setImage(getImage("zl_retake"), for: .normal)
        self.retakeBtn.addTarget(self, action: #selector(retakeBtnClick), for: .touchUpInside)
        self.retakeBtn.isHidden = true
        self.retakeBtn.adjustsImageWhenHighlighted = false
        self.retakeBtn.zl_enlargeValidTouchArea(inset: 30)
        self.view.addSubview(self.retakeBtn)
        
        let cameraCount = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: .unspecified).devices.count
        self.switchCameraBtn.setImage(getImage("zl_toggle_camera"), for: .normal)
        self.switchCameraBtn.addTarget(self, action: #selector(switchCameraBtnClick), for: .touchUpInside)
        self.switchCameraBtn.adjustsImageWhenHighlighted = false
        self.switchCameraBtn.zl_enlargeValidTouchArea(inset: 30)
        self.switchCameraBtn.isHidden = cameraCount <= 1
        self.view.addSubview(self.switchCameraBtn)
        
        self.doneBtn.titleLabel?.font = ZLLayout.bottomToolTitleFont
        self.doneBtn.setTitle(localLanguageTextValue(.done), for: .normal)
        self.doneBtn.setTitleColor(.bottomToolViewBtnNormalTitleColor, for: .normal)
        self.doneBtn.backgroundColor = .bottomToolViewBtnNormalBgColor
        self.doneBtn.addTarget(self, action: #selector(doneBtnClick), for: .touchUpInside)
        self.doneBtn.isHidden = true
        self.doneBtn.layer.masksToBounds = true
        self.doneBtn.layer.cornerRadius = ZLLayout.bottomToolBtnCornerRadius
        self.view.addSubview(self.doneBtn)
        
        let focusCursorTap = UITapGestureRecognizer(target: self, action: #selector(adjustFocusPoint))
        focusCursorTap.delegate = self
        self.view.addGestureRecognizer(focusCursorTap)
        
        if ZLPhotoConfiguration.default().allowRecordVideo {
            let pan = UIPanGestureRecognizer(target: self, action: #selector(adjustCameraFocus(_:)))
            pan.delegate = self
            pan.maximumNumberOfTouches = 1
            self.view.addGestureRecognizer(pan)
            
            self.recordVideoPlayerLayer = AVPlayerLayer()
            self.recordVideoPlayerLayer?.backgroundColor = UIColor.black.cgColor
            self.recordVideoPlayerLayer?.videoGravity = .resizeAspect
            self.recordVideoPlayerLayer?.isHidden = true
            self.view.layer.insertSublayer(self.recordVideoPlayerLayer!, at: 0)
            
            NotificationCenter.default.addObserver(self, selector: #selector(recordVideoPlayFinished), name: .AVPlayerItemDidPlayToEndTime, object: nil)
        }
        
        let pinchGes = UIPinchGestureRecognizer(target: self, action: #selector(pinchToAdjustCameraFocus(_:)))
        self.view.addGestureRecognizer(pinchGes)
    }
    
    func observerDeviceMotion() {

extension ZLCustomCamera: UIGestureRecognizerDelegate {
    
    public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        let gesTuples: [(UIGestureRecognizer?, UIGestureRecognizer?)] = [(recordLongGes, cameraFocusPanGes), (recordLongGes, focusCursorTapGes), (cameraFocusPanGes, focusCursorTapGes)]
        
        let result = gesTuples.map { (ges1, ges2) in
            return (ges1 == gestureRecognizer && ges2 == otherGestureRecognizer) ||
            (ges2 == otherGestureRecognizer && ges1 == gestureRecognizer)
        }.filter { $0 == true}
        
        return result.count > 0
    }
    
}
