TimOliver / TOCropViewController

A view controller for iOS that allows users to crop portions of UIImage objects
http://www.timoliver.com.au/2015/06/21/tocropviewcontroller-an-open-source-image-cropper-for-ios/
MIT License
4.74k stars 955 forks source link

Crop View Controller just dismisses on iPad on any toolbar button press #477

Open nrgbodya opened 3 years ago

nrgbodya commented 3 years ago

Describe the bug Any touch on on toolbar of CropViewController will dismiss it and any of the delegate or callback methods will be called. This happens on iPad only, and I am using CropViewController as described in "Usage". After trying to reproduce the bug in CropViewController Demo App, I wondered why it's not happening there. After studying the difference between the implementation of the Demo App and my app, I got to the conclusion that I was missing the modalPresentationStyle = .popover which is nowhere documented. (or am I wrong?)

To Reproduce Let's take the example Demo App. Just go to the line where the modalPresentationStyleof the imagePicker is set to .popover - currently line 154 in ViewController.swift. Start the CropViewController target on iPad device. Press on plus button -> Make profile picture -> select any picture from Gallery -> when CropViewController is presented, press any button on the toolbar -> it's gone.

Expected behavior Button events will be handled. i.e. press on the Done button sets the background picture in the ViewController.

iOS Device:

Additional context Interestingly enough, if you start the Split Screen mode on the iPad, this bug is not happening any more. Does is have something to do with the iPad anyway?

dani2906 commented 3 years ago

Just noticed it on my app too. Only happens on ios 14 and ipad

dani2906 commented 3 years ago

Any suggestions to fix this?

nrgbodya commented 3 years ago

@dani2906 as a workaround, set the modalPresentationStyle to .popover.

XDChang commented 3 years ago

I also encountered the same problem with iPad iOS 14.4. Clicking the self toolbar Button has no other effect, it just disappears the view.

XDChang commented 3 years ago

I modified the view pop-up method to solve this problem. [picker dismissViewControllerAnimated:YES completion:^{ [self presentViewController:cropController animated:YES completion:nil]; //[self.navigationController pushViewController:cropController animated:YES]; }];

dani2906 commented 3 years ago

I was pushing the viewController. Once changed to present modal it works fine

hardiktgreydesk commented 3 years ago

Hello,

In my case i also face same issue and for ipad i need to change some code to solve this issue. Here is my code. If any one face same issue try below solution.

let iPad = UIDevice.current.userInterfaceIdiom == .pad ? true : false

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let pickedImage = info[.originalImage] as? UIImage {
            let newImage = self.resizeImage(image: pickedImage)

            let cropController = CropViewController(croppingStyle: .default, image: newImage)
            cropController.aspectRatioPreset = .presetSquare
            cropController.aspectRatioPickerButtonHidden = true
            cropController.rotateButtonsHidden = true
            cropController.resetButtonHidden = true
            cropController.aspectRatioLockEnabled = true

            cropController.delegate = self

            if iPad {
                picker.dismiss(animated: true) {
                    self.present(cropController, animated: true, completion: nil)
                }
            }
            else {
                picker.pushViewController(cropController, animated: true)
            }
        }
        else {
            picker.dismiss(animated: true, completion: nil)
        }
    }
benpackard commented 3 years ago

This can also be resolved by setting the modalPresentationStyle to .fullScreen.

beinimaliesi commented 2 years ago

same issue

beinimaliesi commented 2 years ago

resolved.

     if(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            cropController.modalPresentationStyle = UIModalPresentationFullScreen;
        }

        [picker dismissViewControllerAnimated:YES completion:^{
            [[_window rootViewController] presentViewController:cropController animated:YES completion:nil];
        }];