Chapter 19: Challenge Bug?

Hi,

i think the solution provided in the challenge is not working well: after the interactive pop animation of DetailsViewController finishes, the animation seems to carry on for a few more seconds, giving the impression to the user that the app froze.

I resolved the above issue by making the following changes in RevealAnimator.swift:

I replaced this:

override func cancel() {
     restart(forFinishing: false)
     super.cancel()
}

with this:

override func cancel() {
     if operation == .push {restart(forFinishing: false)}
     super.cancel()
}

and this:

override func finish() {
     restart(forFinishing: true)
     super.finish()
}

with this:

override func finish() {
     if operation == .push {restart(forFinishing: true)}
     super.finish()
}

What do you think? :face_with_monocle:

1 Like

As suggested in the book:

“At this point the custom pop transition should be mostly functional. You are using view animations for your pop transition, but view animations don’t need beginTime or completionSpeed to be adjusted. Ensure you don’t modify these properties when the animator operation is .pop.”

In restart(forFinishing:), I wrapped beginTime with a condition like this:

if operation == .push { transitionLayer?.beginTime = CACurrentMediaTime() }

And inside the if interactive { … } block inside animateTransition(using:), I also wrapped speed with a condition:

if operation == .push { transitionLayer.speed = 0 }

It works well. However, I still cannot figure out why we don’t need beginTime and speed when the operation is .pop.

1 Like

Hey anastasioscho! I’ve had the same issue (and was going to start a toping) and your suggestion works for me. Thanks for sharing!

1 Like

They mention this in the book:

Note: It feels like this extra work for layer animations is a UIKit bug; if you don’t use layer animations in the transition, you don’t have to do all this messing about, but under the hood the transition is doing the same sort of thing to make the view animations scrub back and forth.

Maybe implementing custom interactive transition instead of using UIPercentDrivenInteractiveTransition would’ve been a better option for this app.

This topic was automatically closed after 166 days. New replies are no longer allowed.