TOCropViewController
TOCropViewController copied to clipboard
Dismissing a TOCropViewController presented from a not-full-screen VC causes the presenting VC's view to be removed
Describe the bug
I have a presented view controller that is not full-screen that itself presents TOCropViewController. In this configuration, when the TOCropViewController is dismissed, the parent view controller's view is removed, leaving a transparent hole.
Another part of my app has a presented full-screen view controller that also presents a TOCropViewController, which works correctly.
I've tracked this down to -[TOCropViewControllerTransitioning animateTransition:]. Specifically, I see two problems:
- line 49:
if self.isDismissingsets thepreviousController.view.frame = containerView.bounds. This does not appear to be correct in the not-full-screen parent case. With a not-full-screen parent, the parent view's size is set to the wrong size, because the assumption that the previous controller's view frame is the same size as thetransitionContext.containerViewis not correct. As a result, the view is changed to be larger than its container, and so content winds up incorrectly positioned. This is obvious on Mac Catalyst, and it seems to me that this would not be correct on iOS as well (but possibly harder to see because of the smaller size difference), but I have not done any investigation to prove or disprove that. - line 60:
[containerView insertSubview:previousController.view belowSubview:cropViewController.view];: When dismissing, the previous controller's view is moved into the transition container view, but this seems to mean that the view is removed from the previous controller. Thus, when the transition completes, thepreviousControllerhas its view removed, and becomes a transparent hole.
A "fix" for the not-full-screen case is to remove both of those lines, and then it appears to work correctly on both iOS and on Mac Catalyst. However, this is not an adequate fix, because when dismissing to the (otherwise working) full-screen view controller, there's a white flash during the transition that shouldn't be there.
Another "fix" is to remove creating and setting the _transitionController in the TOCropViewController init. In my testing, it appears to work correctly (for both full-screen and not-full-screen presenting VCs), which makes me wonder if the transition controller is even needed in the case that the delegate implements the didFinish/didCrop methods.
iOS Device:
- iOS 14.4.2
- Mac Catalyst on 10.15.7
- TOCropViewController 2.6.0
We are having the same issue! Was working fine on full screen modal presentations, but once switched to presented from non full screen it bugs out. Your suggested fix does work for non full screen presentations parents.
A "fix" for the not-full-screen case is to remove both of those lines, and then it appears to work correctly on both iOS and on Mac Catalyst. However, this is not an adequate fix, because when dismissing to the (otherwise working) full-screen view controller, there's a white flash during the transition that shouldn't be there.
If it's any help here I encapsulate cropViewController in a UINavigationController and it seems to do the trick for now.
let nvc = UINavigationController(rootViewController: cropViewController)
present(nvc, animated: true, completion: nil)
Workaround:
let controller = CropViewController(image: image)
controller.transitioningDelegate = nil
controller.modalTransitionStyle = .crossDissolve
sourceController.present(controller, animated: true)