OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 2.0 UIImagePickerController 在关闭时关闭父 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:27
标题: ios - Swift 2.0 UIImagePickerController 在关闭时关闭父 View

开始使用 Swift 2.0 之前的版本在 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)
}



Best Answer-推荐答案


我在展示一个父 Controller 是 UITabBarControllerUIImagePickerViewController 时遇到了类似的问题,只需将 modalPresentationStyle 设置为 overCurrentContext

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4