0

After presenting SFSafariViewController modally, a user presses the "Done" button and the controller is dismissed with animation. If I implement the delegate and try to dismiss it without animation, it has no effect (still dismissed with animation):

let vc = SFSafariViewController(url: webUrl)
vc.delegate = self
self.present(vc, animated: true)
extension MyCoolViewController: SFSafariViewControllerDelegate {
 func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
 controller.dismiss(animated: true)
 }
}

If I try to dismiss the controller programmatically, it works just great and the animated flag is honored but it I try to do it in the safariViewControllerDidFinish, the animation is playing regardless.

Is it possible to override that behavior and dismiss the SFSafariViewController without animation when a user taps the "Done" button?

asked Apr 16, 2024 at 0:50

1 Answer 1

1

I've tried dismiss(_:), but it seems like it did not have any effect on dismiss style as normal. There is another approach, it's handling transitioningDelegate by yourself:

let vc = SFSafariViewController(url: webUrl)
vc.transitioningDelegate = self
...
extension MyCoolViewController: UIViewControllerTransitioningDelegate {
 func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
 dismissed.view.alpha = 0
 return .none
 }
}

Output:

enter image description here

answered Apr 16, 2024 at 1:32
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.