Fix the background view origin when presenting #183
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When presenting over a ViewController (the “from” VC), if that ViewController is not at the screen’s origin, the background view will not appear at the correct position above it.
This fixes the problem by setting the background view’s frame to the “from” VC’s view’s frame converted into the coordinate system of the container view.
Checklist
Motivation and Context
The issue this fixes is described in Issue #181 .
Before this fix, the frame of the presenting VC's View is being applied to the background view during the transition animation. However, the frame of the presenting VC's View is always going to have an origin of
(x: 0, y: 0)
in it's own coordinate system.If the presenting VC is not actually at the origin of the screen (which will also be the origin of the transition's containerView), then the background will be the same size as the presenting VC but located at the origin, not correctly aligned with the presenting VC.
I've tested this inside a project in a couple of different presenting VC scenarios.
If the old behavior is preferred by the maintainers, no problem. Thanks for sharing this useful library.
Description
This PR fixes that problem by converting the frame into the containerView's coordinate system before applying it to the background view.
Mostly just this:
let fromFrame = containerView.convert(fromView.frame, from: fromView)