presentViewController如何显示视图?

时间:2016-04-17 17:00:44

标签: swift uiimagepickercontroller

我很好奇presentViewController对第一个参数 imagePickerController 的处理方式。鉴于我分配imagePickerController属性的方式,presentViewController是否会使用所有这些信息来显示视图?

@IBAction func imageFromPhotoLibrary(sender: UITapGestureRecognizer) {
    // Hide the keyboard.
    myTextField.resignFirstResponder()

    // UIImagePickerController is a view controller that lets a user pick media from their photo library.
    let imagePickerController = UIImagePickerController()

    // Only allow photos to be picked, not taken.
    imagePickerController.sourceType = .PhotoLibrary

    // Make sure ViewController is notified when the user picks an image.
    imagePickerController.delegate = self

    presentViewController(imagePickerController, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:0)

presentViewController不会使用任何选项。您传入的imagePickerController将使用这些选项。

由于Apple API设计得非常好,presentViewController做了一件事(SRP),并完全按照它的说法做了...... 提供了传递它的视图控制器

imagePickerController负责控制图像选择器的视图