HeroTransitions / Hero

Elegant transition library for iOS & tvOS

Home Page:https://HeroTransitions.github.io/Hero/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

zkfpk6 opened this issue · comments

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?