UIGestureRecognizerDelegate
A set of methods implemented by the delegate of a gesture recognizer to fine-tune an app’s gesture-recognition behavior.
一個設定手勢識別器委托實作的方法,用于微調應用程式的手勢識別行為,
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.
這些委托從手勢識別器接收訊息,它們會回應這些訊息以能夠影響到手勢識別器的操作或指定它與另外一個手勢識別器的關系,例如,允許同時識別或設定動態的失敗需求,
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手勢系結到一個視圖上,在這種情況下,您可能希望與該視圖的子樹關聯的所有其他相關手勢識別器都要求螢屏邊緣手勢識別器失敗,這樣就可以防止在啟動識別程序后取消其他識別器時可能出現的任何圖形錯誤,如果想做到這一點,你可以使用類似于下面的代碼:
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.
詢問委托代理是否允許兩個手勢識別器同時識別手勢,
optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> BoolReturn 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.
如果為真的時候允許手勢識別器與其他手勢識別器同時識別他們的手勢,默認實作回傳false,不能同時識別兩個手勢,
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.
當手勢識別器或其他手勢識別器對某個手勢的識別會阻止其他手勢識別器識別其手勢時,就會呼叫此方法,注意,回傳true保證允許同時識別;另一方面,回傳false不能保證防止同時識別,因為其他手勢識別器的委托可能回傳true,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/7510.html
標籤:iOS
