[IOS] translation of a variety of gestures innocently tell UIGestureRecognizer

 UIGestureRecognizerDelegate

  A set of methods implemented by the delegate of a gesture recognizer to fine-tune an app’s gesture-recognition behavior.  

  Provided a gesture recognition method delegate implemented gesture recognition used to fine tune the behavior of the application.

  Overview

  The delegates receive messages from a gesture recognizer, and their responses to these messages enable them to affect the operation of the gesture recognizer or to specify a relationship between it and another gesture recognizer, such as allowing simultaneous recognition or setting up a dynamic failure requirement.

  These message reception request from the gesture recognition, they will respond to these messages can affect the operation of the gesture recognition or specify its relationship with another gesture recognition, e.g., allowing simultaneous identification of failed or provided a dynamic demand.

  An example of a situation where dynamic failure requirements are useful is in an app that attaches a screen-edge pan gesture recognizer to a view. In this case, you might want all other relevant gesture recognizers associated with that view's subtree to require the screen-edge gesture recognizer to fail so you can prevent any graphical glitches that might occur when the other recognizers get canceled after starting the recognition process. To do this, you could use code similar to the following:

  In the application of dynamic demand fails example, the application will bind the pan gesture edge of the screen to the previous view, in this case, you may want all other relevant gesture recognition device associated with the sub-tree view of all requirements edge of the screen gesture recognition fails, any graphics so you can prevent errors that may occur when other identifier canceled after starting the recognition process. If you want to do this, you can use code like the following:

let myScreenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action:#selector(handleScreenEdgePan))
myScreenEdgePanGestureRecognizer.delegate = self
    // Configure the gesture recognizer and attach it to the view.
 
...
 
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    guard let myView = myScreenEdgePanGestureRecognizer.view,
          let otherView = otherGestureRecognizer.view else { return false }
    
    return gestureRecognizer == myScreenEdgePanGestureRecognizer &&
           otherView.isDescendant(of: myView)}

gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)

  Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.

  Asked the agency whether to allow two simultaneous gesture recognition gesture recognition.

optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool

 Return Value

  true to allow both gestureRecognizer and otherGestureRecognizer to recognize their gestures simultaneously. The default implementation returns false—no two gestures can be recognized simultaneously.

  If it is really time to allow gesture recognition simultaneously identify their gestures and other gestures recognizer. The default implementation returns false, the two can not recognize gestures.

 Discussion

  This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning true is guaranteed to allow simultaneous recognition; returning false, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may return true.

  When the gesture recognizers, or other gesture recognizers to identify a gesture would prevent other gesture recognition recognizes its gesture, it will call this method. Note that, to ensure that allows simultaneous identification returns true; on the other hand, can not be guaranteed while preventing return false recognition, gesture recognition because other delegate may return true.

 

 

Guess you like

Origin www.cnblogs.com/xjf125/p/11965274.html