学习笔记:swift——调用照相机和照片

首先需要引用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)
    }


你可能感兴趣的:(学习笔记:swift——调用照相机和照片)