tempest_fiend
tempest_fiend

Reputation: 35

ToView appearing behind FromView in Swift

I'm doing a fairly simple segue by presenting the next view controller with a custom transition animation.

Essentially, the transition creates the toView off the screen and then slides it over the fromView from the right, while the fromView slides off the left at a slightly slower speed. The dismissing transition does the opposite.

My problem is after dismissing the toView to go back to the fromView, when I trigger the segue again, the toView is sliding under the fromView instead of over. This doesn't happen on the first transition, but happens for everyone of them after.

I cannot for the life of me figure out why it's doing this, let alone how to fix it. Any help would be awesome.

segue code:

let storyboard = UIStoryboard(name: kOnboardingSignupStoryboard, bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: kOnboardingErrorIdentifier) as! OnboardingErrorViewController vc.transitioningDelegate = self vc.errorMessage = kErrorIncorrectPin self.present(vc, animated: true, completion: nil)

dismiss code:

dismiss(animated: true, completion: nil)

transition extension:

extension OnboardingErrorViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return FromRightDeck()
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return DismissFromRightDeck()
}

Gif of the issue

Upvotes: 0

Views: 41

Answers (1)

tempest_fiend
tempest_fiend

Reputation: 35

Ok, so I managed to solve it after diving into the animation code. Initially I didn't think this would have anything to do with it, as it works fine the first time and every other time I use the animation. However, there was an errant line of code pushing to toView z position which I was using in testing, that was causing this issue.

Upvotes: 0

Related Questions