congnd / FMPhotoPicker

A modern, simple and zero-dependency photo picker with an elegant and customizable image editor
MIT License
773 stars 128 forks source link

Need to dismiss twice to dismiss the picker #16

Closed wakaryry closed 4 years ago

wakaryry commented 5 years ago
func openPicker() {
            var config = FMPhotoPickerConfig()
            config.selectMode = .single
            config.mediaTypes = [.image]
            config.forceCropEnabled = true
            config.availableCrops = [FMCrop.ratioSquare]

            let picker = FMPhotoPickerViewController(config: config)
            picker.delegate = self
            self.present(picker, animated: true)
}

func fmPhotoPickerController(_ picker: FMPhotoPickerViewController, didFinishPickingPhotoWith photos: [UIImage]) {

        picker.dismiss(animated: true, completion: nil)
        picker.dismiss(animated: true, completion: nil)
        if photos.count > 0 {
            upload(image: photos.first!)
        }
    }

I want to dismiss the picker after I didFinishPicking, it will call didFinishPicking delegate after I edited my picture, and the dismiss can not dismiss the picker. It's still in the picker page where to select an image.

And then I tap the finish in the first page of the picker, it will call didFinishPicking delegate and then dismiss the picker.

It will call twice didFinishPicking delegate method in my one select and edit. And I can not dismiss the picker with one dismiss. So I use two dismiss to dismiss the picker.

congnd commented 4 years ago

@wakaryry

Sorry for long time no response. For dimissal, you should call the dimiss() on your view controller but not on the picker. Hope this help.

Feel free to reopen it again if you need more help.

IshuRocks commented 3 years ago

For dimissal, use below code

self.dismiss(animated: true, completion: {
            if photos.count > 0 {
            upload(image: photos.first!)
        }
 })