美文网首页Swift
学习笔记:swift——调用照相机和照片

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

作者: 独居焚香 | 来源:发表于2015-12-17 15:57 被阅读1615次

首先需要引用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——调用照相机和照片

    本文链接:https://www.haomeiwen.com/subject/xldphttx.html