美文网首页
5.8、获取系统相册

5.8、获取系统相册

作者: 艾希_可可 | 来源:发表于2018-06-27 11:31 被阅读1次

    import UIKit

    class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
    var imageV = UIImageView()
    // 真机测试,点击window选择虚拟机,然后打勾ok
    override func viewDidLoad() {
    super.viewDidLoad()
    // Privacy - Photo Library Usage Description //相册xxx想访问您的相册
    // Privacy - Camera Usage Description //相机 xxx想访问您的相机
    // Privacy - Microphone Usage Description //麦克风
    // Privacy - Contacts Usage Description //通讯录 xxx想访问您的通讯录
    // Privacy - Location Always Usage Description //持续定位
    // Privacy - Location When In Use Usage Description //使用应用时定位

        let imageView = UIImageView(frame: CGRect(x: 90, y: 150, width: 180, height: 180))
        self.view.addSubview(imageView)
        imageView.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(touchImageView))
        imageView.addGestureRecognizer(tap)
        imageView.backgroundColor = UIColor.yellow
        self.imageV = imageView
    }
    @objc func touchImageView() {
        let photopickController = UIImagePickerController()
        photopickController.delegate = self
        photopickController.sourceType = .photoLibrary //或者访问相册photoLibrary//        NSCameraUsageDescription访问相机
        self.present(photopickController, animated: true) {
            
        }
    }
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        guard let selectImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
            fatalError("-----error")
        }
        self.imageV.image = selectImage
        picker.dismiss(animated: true) {
            
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    }

    相关文章

      网友评论

          本文标题:5.8、获取系统相册

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