zoukankan      html  css  js  c++  java
  • 用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()

            }

        }

        

       

  • 相关阅读:
    字付串函数 substring(ex,star,end)
    OBJECT_ID临时表无效
    行列转换
    字符串类型系统函数
    exec sql
    系统函数 1
    常见排序算法-----简单选择排序
    排序概念------排序的稳定性
    JAVA学习-参数传递
    常见排序算法-----二分插入排序
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/22-.html
Copyright © 2011-2022 走看看