A set of methods implemented by the delegate of a gesture recognizer to fine-tune an app’s gesture-recognition behavior. app
一個設置手勢識別器委託實現的方法,用於微調應用程序的手勢識別行爲。ui
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.this
這些委託從手勢識別器接收消息,它們會響應這些消息以可以影響到手勢識別器的操做或指定它與另一個手勢識別器的關係,例如,容許同時識別或設置動態的失敗需求。spa
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:代理
在應用程序中動態的失敗需求例子,應用程序將屏幕邊緣的pan手勢綁定到一個視圖上,在這種狀況下,您可能但願與該視圖的子樹關聯的全部其餘相關手勢識別器都要求屏幕邊緣手勢識別器失敗,這樣就能夠防止在啓動識別過程後取消其餘識別器時可能出現的任何圖形錯誤。若是想作到這一點,你能夠使用相似於下面的代碼:code
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)}
Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.orm
詢問委託代理是否容許兩個手勢識別器同時識別手勢。blog
optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool
true
to allow both gestureRecognizer
and otherGestureRecognizer
to recognize their gestures simultaneously. The default implementation returns false
—no two gestures can be recognized simultaneously.ip
若是爲真的時候容許手勢識別器與其餘手勢識別器同時識別他們的手勢。默認實現返回false,不能同時識別兩個手勢。ci
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
.
當手勢識別器或其餘手勢識別器對某個手勢的識別會阻止其餘手勢識別器識別其手勢時,就會調用此方法。注意,返回true保證容許同時識別;另外一方面,返回false不能保證防止同時識別,由於其餘手勢識別器的委託可能返回true。