Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Hero use swipe back gesture animation like UINavigationController default swipe back gesture animation in a presenting controller? #713

Open
zkfpk6 opened this issue Mar 12, 2021 · 0 comments

Comments

@zkfpk6
Copy link

zkfpk6 commented Mar 12, 2021

First sorry for my bad English.
Here is my code:
`

@objc func hero_setPushAnimationType() {
    self.hero.modalAnimationType = .selectBy(presenting: .push(direction: .left), dismissing: .push(direction: .right))
    self.hero.isEnabled = true
}

@objc func enableSwipeBackWhenPresent(WithFinishDismissBlock finishDismissBlock: (() -> Void)?) {
    self.heroDismissBlock = finishDismissBlock
    let gesture = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(swipe(_:)))
    gesture.edges = .left
    self.view.addGestureRecognizer(gesture)
}

@objc func swipe(_ gesture:UIScreenEdgePanGestureRecognizer) {
    switch gesture.state {
    case .began:
        self.dismiss(animated: true, completion: nil)
    case .changed:
        let progress = gesture.translation(in: nil).x / self.view.bounds.width
        Hero.shared.update(progress)
    default:
        if (gesture.translation(in: nil).x + gesture.velocity(in: nil).x) / self.view.bounds.width > 0.5 {
            self.dismiss(animated: true, completion: nil)
            Hero.shared.finish()
            if (self.heroDismissBlock != nil) {
                self.heroDismissBlock!()
            }
        } else {
            Hero.shared.cancel()
        }
    }
}

`

Now i can swipe back very similar to UINavigationController, but because of the animation is not linear animation, current controller not tracking while my finger's movement, so how to fix it?

@JoeMatt JoeMatt changed the title Cound hero use swipe back gesture animation like UINavigationController default swipe back gesture animation in a presenting controller? Can Hero use swipe back gesture animation like UINavigationController default swipe back gesture animation in a presenting controller? Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants