ios - Swift 2.0 UIImagePickerController 在关闭时关闭父 View

标签 ios xcode uiimagepickercontroller swift2

开始使用 2.0 之前版本的 swift 在 Xcode 6.* 中开发应用程序。自从更新到 Xcode 7.0 和 swift 2.0 以来,我的应用程序的行为不符合预期。

在我的应用程序中,我有一个典型的用户设置 View ,它被推送到我的 NavigationController 上,如下所示:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let view = storyBoard.instantiateViewControllerWithIdentifier("settingsView")
controller.navigationController?.setViewControllers([view], animated: false)

当用户点击其个人资料图像时,将显示 UIImagePickerController。然而现在,如果用户点击取消或选择图像,图像 Controller 将被关闭,但用户设置 Controller 也会被关闭。究竟为什么会突然发生这种情况(在 Xcode 更新之前它按预期工作)。

处理图片选择的代码如下所示:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        self.imageUrl = info[UIImagePickerControllerReferenceURL] as! NSURL
        self.Picture.contentMode = .ScaleAspectFill
        self.Picture.image = pickedImage
        self.PictureChosen = true
    }

    dismissViewControllerAnimated(true, completion: nil)
}

最佳答案

我在提交 UIImagePickerViewController 时遇到了类似的问题哪个父 Controller 是 UITabBarController ,只需设置 modalPresentationStyleoverCurrentContext

let imagePicker = UIImagePickerController()
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = false
imagePicker.delegate = self
imagePicker.modalPresentationStyle = .overCurrentContext
present(imagePicker, animated: true, completion: nil)

关于ios - Swift 2.0 UIImagePickerController 在关闭时关闭父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878425/

相关文章:

ios - 图像是由 UIImagePickerControllerSourceTypeCamera 拍摄的如何将其保存在 ios 的数据库中

ios - 为一年中的每一天生成 View Controller

iphone - UICollectionView 单元格 Nib 未加载

ios - 'UIImageView' 没有可见的@interface 声明选择器 'setImageWithURL'

ios - 如何使用 UIImagePickerController 将视频上传到服务器

ios - UIImagePicker 给出运行时错误

ios - 使用 MapKit 框架在谷歌地图上绘制多边形

iphone - iOS 开发 : What's a simple way to calculate the number of seconds that have passed between two events?

ios - UIButton 动画后没有响应

ios - 如何将一个 UIImageView 的图像设置为另一个 UIImageview 的图像