我第一次尝试使用外部库WDImagePicker。下面是与我的问题相关的WDImagePicker代码。
@objc public protocol WDImagePickerDelegate {
@objc optional func imagePicker(imagePicker: WDImagePicker, pickedImage: UIImage)
@objc optional func imagePickerDidCancel(imagePicker: WDImagePicker)
}
@objc public class WDImagePicker: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate, WDImageCropControllerDelegate {
public var delegate: WDImagePickerDelegate?
private var _imagePickerController: UIImagePickerController!
public var imagePickerController: UIImagePickerController {
return _imagePickerController
}
override public init() {
super.init()
self.cropSize = CGSize(width: 320, height: 320)
_imagePickerController = UIImagePickerController()
_imagePickerController.delegate = self
_imagePickerController.sourceType = .photoLibrary
}
public func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
print("this line never runs\n\n")
}
}
在我自己写的控制器中,我有这个方法,它提供了cropImagePicker的imagePickerContoller;但即使此控制器的委托是cropImagePicker,cropImagePicker的ImagePickerControllerDelegate方法永远不会被调用(我测试了所有这些)。
@IBAction func cameraButtonPressed() {
let cropImagePicker = WDImagePicker()
cropImagePicker.cropSize = CGSize(width: 50, height: 50)
cropImagePicker.delegate = self
cropImagePicker.resizableCropArea = false
cropImagePicker.imagePickerController.delegate = cropImagePicker
self.present(cropImagePicker.imagePickerController, animated: true, completion: nil)
}
为什么会这样?可能是因为我必须对图书馆进行迅速的3次更改吗?最重要的是,我该如何解决这个问题呢?所有的意见都表示赞赏。