I have two WKWebView objects that are subviews in my main view hierarchy. I'm very new to Swift so I don't know much, but I'm trying to transition between these two views and everything works perfectly except when I swipe to the right, the left swipe does the animation as expected but the right does nothing then snaps to the page.
func animateTranstion(fromLeft: Bool) {
let webViewToShow: WKWebView
let webViewToHide: WKWebView
let transitionOption: UIView.AnimationOptions
if fromLeft {
webViewToShow = webViewB
webViewToHide = webViewA
transitionOption = .transitionCrossDissolve
} else {
webViewToShow = webViewA
webViewToHide = webViewB
transitionOption = .transitionCrossDissolve
}
guard webViewToHide.isHidden == false else {
return
}
UIView.transition(with: webViewToShow, duration: 0.5, options: transitionOption, animations:) {
webViewToShow.isHidden = false
}) { _ in
webViewToHide.isHidden = true
}
}
I've tried using .alpha instead of .isHidden, I tried changing the duration and changing the animation, and even just hard coding the animation into the option. I followed the variables down to this function and all the objects are correct, it knows which to hide and show and where, but for whatever reason the animation just isn't happening?
UIView.transition(with: webViewToShow, duration: 0.5, options: transitionOption, animations:) {
webViewToShow.isHidden = false
webViewToHide.isHidden = true
})
I ended up changing this function call and now the transition plays in both directions.