2015-09-29 16 views
7

?, örneğin, şu anda benim kamera önizleme tabakası I karedir kamera odaklanmasını ve pozlamayı o çerçeveye bağlı olarak belirtilmesini ister. Mümkünse Swift 2'de buna ihtiyacım var, eğer cevabınızı yazmazsanız, bunu kendim çevirebilirim.Otomatik Odaklama ve AVFoundation Otomatik Poz Özel Kamera Katmanı doğru <strong>Otomatik Odaklama ve <strong>AVFoundation</strong> Özel katman kamera için Pozlama</strong> oluşturmak için en iyi yolu nedir

Geçerli Otomatik Odaklanma ve Pozlama: Ancak, gördüğünüz gibi bu, odaklama sırasında tüm görünümü değerlendirecektir.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    //Get Touch Point 
    let Point = touches.first!.locationInView(self.capture) 
    //Assign Auto Focus and Auto Exposour 
    if let device = currentCameraInput { 
     do { 
      try! device.lockForConfiguration() 
      if device.focusPointOfInterestSupported{ 
       //Add Focus on Point 
       device.focusPointOfInterest = Point 
       device.focusMode = AVCaptureFocusMode.AutoFocus 
      } 

      if device.exposurePointOfInterestSupported{ 
       //Add Exposure on Point 
       device.exposurePointOfInterest = Point 
       device.exposureMode = AVCaptureExposureMode.AutoExpose 
      } 
      device.unlockForConfiguration() 
     } 
    } 
} 

Kamera Katman: 1'de şey: 1 oranında bile kamera odak için dokunmatik olay olarak düşünülebilir olmaz bağlı bu dış odak ve pozlama noktası ve bir şey olarak kabul edilmelidir.

+2

AVCaptureVideoPreviewLayer kullanıyor musunuz? Eğer öyleyse: 'public func captureDevicePointOfInterestForPoint (pointInLayer: CGPoint) -> CGPoint' – jlw

+0

@ jlw Evet' AVCaptureVideoPreviewLayer' kullanıyorum ama bu işlevi görmüyorum. :/ – Xrait

+1

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/#//apple_ref/occ/instm/AVCaptureVideoPreviewLayer/captureDevicePointOfInterestForPoint: – jlw

cevap

8
public func captureDevicePointOfInterestForPoint(pointInLayer: CGPoint) -> CGPoint 

enter image description here

sizin AVCaptureVideoPreviewLayer ayarlarını temel odaklanmak cihaz için size puan verecek. docs'a bakın.

+0

Tekrar teşekkürler. – Xrait

7

Buraya JLW sayesinde Swift 2'de bunu gerçekleştirebilirsiniz. İlk olarak, bu program aracılığıyla veya Storyboard'da yapabileceğiniz Dokunma hareketini ayarlamanız gerekir.

//Add UITap Gesture Capture Frame for Focus and Exposure 
    let captureTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "AutoFocusGesture:") 
    captureTapGesture.numberOfTapsRequired = 1 
    captureTapGesture.numberOfTouchesRequired = 1 
    self.captureFrame.addGestureRecognizer(captureTapGesture) 

captureTapGesture bizim seçici üzerinde bir işlev tabanını oluşturun. Eğer animasyon göstergesini kullanmak isterseniz

/*========================================= 
* FOCUS & EXPOSOUR 
==========================================*/ 
var animateActivity: Bool! 
internal func AutoFocusGesture(RecognizeGesture: UITapGestureRecognizer){ 
    let touchPoint: CGPoint = RecognizeGesture.locationInView(self.captureFrame) 
    //GET PREVIEW LAYER POINT 
    let convertedPoint = self.previewLayer.captureDevicePointOfInterestForPoint(touchPoint) 

    //Assign Auto Focus and Auto Exposour 
    if let device = currentCameraInput { 
     do { 
      try! device.lockForConfiguration() 
      if device.focusPointOfInterestSupported{ 
       //Add Focus on Point 
       device.focusPointOfInterest = convertedPoint 
       device.focusMode = AVCaptureFocusMode.AutoFocus 
      } 

      if device.exposurePointOfInterestSupported{ 
       //Add Exposure on Point 
       device.exposurePointOfInterest = convertedPoint 
       device.exposureMode = AVCaptureExposureMode.AutoExpose 
      } 
      device.unlockForConfiguration() 
     } 
    } 
} 

Ayrıca, bir olayın sizin dokunarak temas noktası kullanmak ve animasyon katmana atayın.

//Assign Indicator Position 
touchIndicatorOutside.frame.origin.x = touchPoint.x - 10 
touchIndicatorOutside.frame.origin.y = touchPoint.y - 10 
İlgili konular