Hero: Screen freezes (no crash just frozen)
I have implemented this logic on view controller A with presents view controller B. View controller be will sometimes just fail to dismiss and remain stuck on screen with no way out except by force killing the app. This does not cause any exception just a frozen app.
View controller A presenting B:
let vc = PrizeDetailsViewController() vc.hero.isEnabled = true vc.hero.modalAnimationType = .selectBy(presenting: .pageIn(direction: .left), dismissing: .pageOut(direction: .right))
This is the dismiss logic for view controller B, it has a pan gesture recognizer and a back button. A and B are regular UIViewController (no UINavigationController).
dismiss logic in B:
func backButtonPressed(sender: UIButton) { hero.dismissViewController() }
`func handlePan(gestureRecognizer:UIPanGestureRecognizer) { let translation = panGR.translation(in: nil) let progress = translation.x / 2 / view.bounds.width
if translation.x < 0 {
Hero.shared.cancel()
}
switch panGR.state {
case .began:
// begin the transition as normal
//dismiss(animated: true, completion: nil)
hero.dismissViewController()
case .changed:
Hero.shared.update(progress)
// update views' position (limited to only vertical scroll)
Hero.shared.apply(modifiers: [.position(CGPoint(x:translation.x/2.0 + view.center.x, y:view.center.y))], to: view)
// Hero.shared.apply(modifiers: [.position(CGPoint(x:nameLabel.center.x, y:translation.y + nameLabel.center.y))], to: nameLabel)
// Hero.shared.apply(modifiers: [.position(CGPoint(x:descriptionLabel.center.x, y:translation.y + descriptionLabel.center.y))], to: descriptionLabel)
default:
// end or cancel the transition based on the progress and user's touch velocity
if progress + panGR.velocity(in: nil).x / view.bounds.width > 0.3 {
Hero.shared.finish()
} else {
Hero.shared.cancel()
}
}
}`
This works 90% of the time but for some reason will just stop randomly. I am wondering if I am setting it up properly.
Thanks
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 25 (3 by maintainers)
Call “finish()” on the main thread. This solved my problem when I use push transitions
@jjjeeerrr111 @petard @emrekaranfil @ManueGE @kluku @tifroz @pablogeek
Any solution on this facing same issue with latest version of library on fast swipe I am using navigation controller and push
Calling
finishandcancellike this solved the problem for me:I was already calling them on the main thread (tested) so it must have been this
asyncthat helped…I have this problem. But not often work. I follow this topic.
Thanks @ManueGE I had the exact same issue - substituting a push transition with a modal transition fixed it!
Details of my implementation: interactive transition driven by a
UIPanGestureRecognizer(panning too fast causes the UI to freeze quite frequently, either when bringing up the new screen or when dismissing it) - in my case noPageViewControllerinvolved, but I do have a view controller hierarchy with parent & child view controllersHaving exactly the same issue with a very similar code. I also have a
PageViewControlleras @petard.It seems that the view controller is properly dismissed (or popped) but there are a snapshot of the view controller on the screen which does nothing. Also, that snapshot does not appear in the view inspector.
@petard @jjjeeerrr111 did you find any solution for this?