TOCropViewController icon indicating copy to clipboard operation
TOCropViewController copied to clipboard

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

Open nrgbodya opened this issue 4 years ago • 10 comments

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:

  • Device: [i.e. iPad Pro 4th generation]
  • OS: [e.g. iOS14.3]
  • Library Version [2.6.1]

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?

nrgbodya avatar Feb 08 '21 14:02 nrgbodya

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

dani2906 avatar Apr 12 '21 00:04 dani2906

Any suggestions to fix this?

dani2906 avatar Apr 12 '21 00:04 dani2906

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

nrgbodya avatar Apr 12 '21 06:04 nrgbodya

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 avatar Apr 17 '21 03:04 XDChang

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]; }];

XDChang avatar Apr 17 '21 04:04 XDChang

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

dani2906 avatar Apr 21 '21 18:04 dani2906

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)
        }
    }

hardiktgreydesk avatar Jun 18 '21 11:06 hardiktgreydesk

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

benpackard avatar Jun 30 '21 15:06 benpackard

same issue

beinimaliesi avatar Dec 19 '21 14:12 beinimaliesi

resolved.

     if(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            cropController.modalPresentationStyle = UIModalPresentationFullScreen;
        }
        
        [picker dismissViewControllerAnimated:YES completion:^{
            [[_window rootViewController] presentViewController:cropController animated:YES completion:nil];
        }];

beinimaliesi avatar Dec 19 '21 15:12 beinimaliesi