• 用swift 写的相机手动对焦


    //对焦十字

            focalView=UIView(frame: CGRectMake(10, 50, 200, 200))

           focalView.backgroundColor = UIColor.clearColor()

            self.overlayView.addSubview(focalView)

            //十字

            let line1 = UIView(frame:CGRectMake(0, 29.5, 60, 1))

            line1.backgroundColor = UIColor.whiteColor()

            focalView.addSubview(line1)

            let line2 = UIView(frame:CGRectMake(29.5, 0, 1, 60))

            line2.backgroundColor = UIColor.whiteColor()

            focalView.addSubview(line2)

            //默认隐藏

            focalView.hidden=true;

            //点击屏幕对焦的手势

            let tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")

            [imagePickerController!.cameraOverlayView? .bringSubviewToFront(self.overlayView)];

            

            self.overlayView.addGestureRecognizer(tapGesture)

        }

        

        func threadInMainMethod(sender : AnyObject)

        {

            GPSLabel.text="GPS精度:中精度"

            directionPrecisionLabel.text = "方向精度:中精度"

            let appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate

            latitudeLabel.text = NSString(format: "纬度:%f" , appdelegate.starpoint.x) as String

            longitudeLabel.text = NSString(format: "经度:%f" , appdelegate.starpoint.y) as String

            let receiver = VideoReceiver.getInstance()

            let wrapper = receiver.rotationWrapper

            let yaw = wrapper.yaw

            let roll = wrapper.roll

            let degree = (yaw - roll + 360)%360

            let direction = parseDirection(degree)

            directionLabel.text =  NSString(format: "方向:%@" , direction) as String

            

        }

             func handleTapGesture(sender: UITapGestureRecognizer){

               

                

            let location:CGPoint!  = sender.locationInView(self.overlayView)

                    focusOnPoint(location, completionHandler: {

                            self.focalView.center = location

                            self.focalView.alpha = 0.0

                            self.focalView.hidden = false

                            UIView.animateWithDuration(1, animations: {

                               self.focalView.alpha = 1.0

                                }, completion: { (finished) in

                                    self.focalView.alpha = 0.0

                            })

                        

                    })

                  

                }

                

         func focusOnPoint(_point: CGPoint, completionHandler: (Void) -> Void) {

            let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)

            

            var pointOfInterest = CGPoint.zero

            let frameSize = self.overlayView.bounds.size

            pointOfInterest = CGPoint(x: _point.y / frameSize.height, y: 1 - (_point.x / frameSize.width))

            if device?.focusPointOfInterestSupported == true && device?.isFocusModeSupported(.AutoFocus) == true {

                do {

                    try device?.lockForConfiguration()

                    

                    if device?.isWhiteBalanceModeSupported(.ContinuousAutoWhiteBalance) == true {

                        device?.whiteBalanceMode = .ContinuousAutoWhiteBalance

                    }

                    

                    if device?.isFocusModeSupported(.ContinuousAutoFocus) == true {

                        device?.focusMode = .ContinuousAutoFocus

                        device?.focusPointOfInterest = pointOfInterest

                    }

                    

                    if device?.exposurePointOfInterestSupported == true && device?.isExposureModeSupported(.ContinuousAutoExposure) == true {

                        device?.exposurePointOfInterest = pointOfInterest

                        device?.exposureMode = .ContinuousAutoExposure

                    }

                    

                    device?.unlockForConfiguration()

                    

                    completionHandler()

                } catch {

                   

                }

            } else {

                completionHandler()

            }

        }

        

       

  • 相关阅读:
    时光流年(4)向往
    Vue.js入门(9)组件插槽
    时光流年(3)古韵
    Java面试题(12)哈希表
    Java面试题(11)Java中hashCode方法的作用
    Java面试题(10)Java中==、equals()、compareTo()的区别
    Java MyBatis-Plus(1)
    Vue.js入门(8)watch、computed和methods之间的区别
    Java面试题(9)常用工具
    Java MyBatis3(11)逆向工程--MyBatis Generator
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/22-.html
Copyright © 2020-2023  润新知