andreamazz / BubbleTransition

A custom modal transition that presents and dismiss a controller with an expanding bubble effect.
MIT License
3.32k stars 250 forks source link

Is it possible to accept gesture while animating? #57

Closed s951736 closed 4 years ago

s951736 commented 5 years ago

Hi, thanks for sharing the great work. It works well on my project, but my project needs the ability to keep accepting gestures of the user, wondering if this can be done with Bubble Transition?

andreamazz commented 5 years ago

Hey @s951736 it should work fine, but it's hard to tell without more details. On top of my mind I could suggesting impelmenting the gesture's delegate method:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) {
  return true
}
s951736 commented 5 years ago

Hello, I should provide more detail. Now my project is pretty simple, there are only two VC in it, and first VC has a button which triggers the segue with bubble transition (just like the demo project). The second VC has an UITapGestureRecognizer that detect tap for the whole VC. I hope the second VC can start to detect user's tapping right after the button in first VC been pressed, even when the bubble animation is running. (Now the animation duration is set to 0.5 as default so in this period of time it can't receive user's tapping)

Sorry, I'm pretty new to coding, so I can't fully understand the method you provided above, I tried adding the code to second VC but it still not accept gesture while animating.

Any suggestion would be appreciated!

andreamazz commented 5 years ago

In your second VC set the delegate of the gesture to self, something like this:

someGesture.delegate = self

then add protocol conformity to your controller and add the aforementioned method. I like to do so in a separate extension at the bottom of the file:

extension SecondViewController: UIGestureRecognizerDelegate {
  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
  }
}

Change SecondViewController with your controller's name

s951736 commented 5 years ago

Thanks for the reply. I tried the code but it seems not working. The second VC conformed to UIGestureRecognizerDelegate itself, so I add the func to the VC directly without using the extension, here is the code:

//TapVC is the second VC

class TapVC: UIViewController, UIGestureRecognizerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
        tap.delegate = self 
        self.view.addGestureRecognizer(tap)
    }    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
}
andreamazz commented 5 years ago

Does the gesture work if you use a standard transition? Because I reckon this is not an issue with this lib.

andreamazz commented 4 years ago

Closing this for inactivity, reopen if you have more info.