2016-03-08 45 views
0

我试图编写一个应用程序,需要一个屏幕,你可以采取多张照片。我使用了http://makeapppie.com/2015/11/04/how-to-make-xib-based-custom-uiimagepickercontroller-cameras-in-swift/的代码示例。我的imagePickerController didFinishPickingMediaWithInfo新被调用

它似乎工作正常,但我的imagePickerController didFinishPickingMediaWithInfo新被调用。我收到来自Xcode的错误消息“将未呈现的视图快照为空快照,确保您的视图在屏幕更新后的快照或快照前至少呈现过一次。”在我看来,这可能是问题所在,我已经使用了它,但没有任何明智之举。很多人写这是一个苹果的错误,我没有找到任何人提供解决方案。

所以,不要任何人知道这是否是Xcode错误这是我的问题,而在这种情况下,有一个解决方案或有我写的东西错在我的代码:

import UIKit 

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CustomOverlayDelegate { 
    var picker = UIImagePickerController() 

    @IBAction func shootPhoto(sender: AnyObject) { 
     if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil { 
      picker = UIImagePickerController() //make a clean controller 
      picker.allowsEditing = false 
      picker.sourceType = UIImagePickerControllerSourceType.Camera 
      picker.cameraCaptureMode = .Photo 
      picker.showsCameraControls = false 

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

      //presentation of the camera 
      picker.modalPresentationStyle = .FullScreen 
      presentViewController(picker, animated: true,completion: { 
       self.picker.cameraOverlayView = customView 
      }) 

     } else { //no camera found -- alert the user. 
      let alertVC = UIAlertController(
       title: "No Camera", 
       message: "Sorry, this device has no camera", 
       preferredStyle: .Alert) 
      let okAction = UIAlertAction(
       title: "OK", 
       style:.Default, 
       handler: nil) 
      alertVC.addAction(okAction) 
      presentViewController(
       alertVC, 
       animated: true, 
       completion: nil) 
     } 
    } 

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
     print("didFinishPickingMediaWithInfo") 
     let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage //get the image from info 
     UIImageWriteToSavedPhotosAlbum(chosenImage, self,nil, nil) //save to the photo library 
    } 

    //What to do if the image picker cancels. 
    func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
     dismissViewControllerAnimated(true, completion: nil) 
    } 

    //MARK: Custom View Delegates 
    func didCancel(overlayView:CustomOverlayView) { 
     picker.dismissViewControllerAnimated(true, completion: nil) 
     print("dismissed!!") 
    } 
    func didShoot(overlayView:CustomOverlayView) { 
     picker.takePicture() 
     overlayView.cameraLabel.text = "Shot Photo" 
     print("Shot Photo") 
    } 
    func weAreDone(overlayView: CustomOverlayView) { 
     picker.dismissViewControllerAnimated(true, 
      completion: nil) 
     print("We are done!") 
    } 
} 

回答

0

picker.delegate = self

picker = UIImagePickerController()线

而且继承你类UIImagePickerControllerDelegate委托。

它会工作。

相关问题