首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置不同动作的相机按钮swift 3

设置不同动作的相机按钮swift 3
EN

Stack Overflow用户
提问于 2017-03-30 05:12:33
回答 1查看 297关注 0票数 0

我正在创建一个应用程序,我打开相机作为第一件事。我能够做到这一点。一旦用户拍摄了照片,他就会看到两个选项,“使用照片”或“取消”。我的问题是,我如何在swift 3中编写代码来设置“使用照片”按钮以方便我,比如将照片存储到图库中,或者其他一些操作。请推荐一些代码来做这件事。谢谢!

下面是我用来打开摄像头的代码:

代码语言:javascript
复制
class ViewController: UIViewController, UINavigationControllerDelegate,         UIImagePickerControllerDelegate {
        override func viewDidAppear(_ animated: Bool) {
            if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
                let image = UIImagePickerController() 
                image.delegate = self  
                image.sourceType = UIImagePickerControllerSourceType.camera   
                image.allowsEditing = false
                self.present(image, animated: true)
            } else {
                print("This device does not support camera")
            }
        }
   }


  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {  
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        myImageView.image = image
    }
    else {
        //Error message
    }
    self.dismiss(animated: true, completion: nil)
    print("camera is dismissed or not")
}
EN

回答 1

Stack Overflow用户

发布于 2017-03-30 05:17:19

我的问题是,我如何在swift 3中编写代码,以便将“使用照片”按钮设置为我的方便,比如将照片存储到图库,或者其他一些操作。

您已经将ViewController设置为图像拾取器控制器的委托,因此只需在ViewController中实现image​Picker​Controller(_:​did​Finish​Picking​Media​With​Info:​)方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43104243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档