这是一个简单的单一视图,单个ViewController
测试应用。此应用在ViewController
中有一个按钮。访问PhotoLibrary
并未显示任何泄漏,但camera
在显示时会显示一些泄漏,在解除时会显示更多泄漏。
这是代码:
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
let pickerCntrl = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
pickerCntrl.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func takePic(_ sender: Any) {
pickerCntrl.sourceType = UIImagePickerControllerSourceType.camera
pickerCntrl.cameraCaptureMode = .photo
pickerCntrl.allowsEditing = true
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)){
self.present(pickerCntrl, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// let editedCapture = info[UIImagePickerControllerEditedImage] as! UIImage?
// let origCapture = info[UIImagePickerControllerOriginalImage] as! UIImage?
self.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
self.dismiss(animated: true, completion: nil)
}
}