Hero icon indicating copy to clipboard operation
Hero copied to clipboard

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

Open zkfpk6 opened this issue 3 years ago • 0 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?

zkfpk6 avatar Mar 12 '21 08:03 zkfpk6