首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios相机应用swift 3

ios相机应用swift 3
EN

Stack Overflow用户
提问于 2016-12-21 04:13:48
回答 0查看 598关注 0票数 0

我想在我的应用程序中有一个具有捕获和保存图像功能的相机界面,但当我运行这个应用程序时,我无法获得任何东西,构建成功,没有任何错误,但在viewController上什么都没有显示。

代码语言:javascript
复制
class ViewController: UIViewController , UINavigationControllerDelegate, UIImagePickerControllerDelegate{

@IBOutlet var imageView: UIImageView!


@IBOutlet var TakePhoto: UIButton!
var imagePick: UIImagePickerController!
var newMedia: Bool?

@IBAction func TakePhoto(_ sender: AnyObject){

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
        let imagePick = UIImagePickerController()
        imagePick.delegate = self
        imagePick.sourceType = UIImagePickerControllerSourceType.camera
        imagePick.mediaTypes = [kUTTypeImage as String]
        imagePick.allowsEditing = false

        self.present(imagePick, animated: true, completion: nil)

        newMedia = true

    }

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let mediaType = info[UIImagePickerControllerMediaType] as! NSString
    if mediaType.isEqual(to: kUTTypeImage as String){
        let image = info[UIImagePickerControllerOriginalImage] as! UIImage
        imageView.image = image

        if(newMedia == true){
           UIImageWriteToSavedPhotosAlbum(image, self, #selector(ViewController.image(image:didFinishSavingWithError:contextInfo:)), nil)
        } //else if mediaType.isEqual(to: kUTTypeMovie as String)

        self.dismiss(animated: true, completion: nil)

    }
}

func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafeRawPointer){
    if error != nil{
        let alert = UIAlertController(title: "Save Failed", message: "Failed to save the image", preferredStyle: UIAlertControllerStyle.alert)

        let cancelAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)

        alert.addAction(cancelAction)
        self.present(alert, animated: true, completion: nil)
    }
}

}

EN

回答

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

https://stackoverflow.com/questions/41250547

复制
相关文章

相似问题

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