Swift - UIImagePickerController - how to use it?

前端 未结 5 2082
天涯浪人
天涯浪人 2020-12-05 02:05

I am trying hard to understand how this works, but it\'s pretty hard for me. =) I have 1 view, there is one button and one small ImageView area for preview. The button trigg

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 02:31

    Since swift 4.2 and xcode 10 the func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) change a bit.

    at the function header the infoKey-Section changes from

    didFinishPickingMediaWithInfo info: [String : Any] to

    didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]

    To get the originalImage you now have to call:

    let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage or

    let image = info[.originalImage] as? UIImage

    find other infoKeys here (editedImage, imageURL and more...)

提交回复
热议问题