首先需要引用UIImagePickerControllerDelegate,UINavigationControllerDelegate
//定义两个图片获取方法
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
self.dismissViewControllerAnimated(true, completion: nil)
self.image_1.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerControllerDidCancel(picker: UIImagePickerController){
self.dismissViewControllerAnimated(true, completion: nil)
}
//调用照片方法
func photo(){
let pick:UIImagePickerController = UIImagePickerController()
pick.delegate = self
pick.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(pick, animated: true, completion: nil)
}
//调用照相机方法
func camera(){
let pick:UIImagePickerController = UIImagePickerController()
pick.delegate = self
pick.sourceType = UIImagePickerControllerSourceType.Camera
self.presentViewController(pick, animated: true, completion: nil)
}
网友评论