iOS UIImagePickerController和TakePicture问题

时间:2016-02-22 21:27:42

标签: ios xcode swift image uiimagepickercontroller

我尝试使用Xcode创建一个简单的应用程序,并使用按钮快速创建。当用户按下按钮时,拍摄照片,显示在屏幕上并保存在iPad的相机胶卷中。我希望有一个自定义界面,因此我不想使用标准的imagePicker。

我已经设置了一些代码试图查看" takePicture"方法,但我无法使其发挥作用:

var imagePicker: UIImagePickerController!
@IBAction func takePhoto(sender: UIButton) {
  imagePicker =  UIImagePickerController()
  imagePicker.delegate = self
  imagePicker.sourceType = .Camera
  imagePicker.cameraDevice = .Front
  imagePicker.cameraOverlayView = self.view
  imagePicker.showsCameraControls = false
  imagePicker.takePicture()
}

我想在执行时会拍摄照片,之后我想使用UIImageWriteToSavedPhotosAlbum函数,但我无法弄清楚如何访问图片。

1 个答案:

答案 0 :(得分:0)

你应该实现:

func imagePickerController(picker: UIImagePickerController,
      didFinishPickingMediaWithInfo info: [String : AnyObject])
{
     let image = info[UIImagePickerControllerOriginalImage]
     //do something with the image or if you want the user to edit the image first
     let editedImage = info[UIImagePickerControllerEditedImage]
}

拍摄照片后将调用此方法。您需要呈现UIImagePickerController。如果您想要自定义UI,可以使用cameraOverlayView提供一个。