System Gesture Interaction
- tap, pinch, rotate, long press 与 system gesture recognizer同时进行
- pan, swipe 在 system gesture recognizer 之后进行
- System gesture or app gesture? Use New API.
class MyViewController: UIViewController {
// override to return which screen edges to defer system gestures
override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
return deferControlCenter ? .bottom : UIRectEdge()
}
// call whenever your method would return a different screen edge
var deferControlCenter : Bool {
didSet { setNeedsUpdateOfScreenEdgesDeferringSystemGestures() }
}
}
For Containers Only:
class MyContainerViewController: UIViewController {
// override to return which child view controller to consult
override func childViewControllerForScreenEdgesDeferringSystemGestures() -> UIViewController? {
return mySelectedChildViewController
}
}
Playing Nice With Drag and Drop
- 添加 drag interaction 到 view 的interaction array,drag interaction 创建一些 gesture recognizers 添加到view上,并将自己设置为gesture recognizers 的delegate.
-
在View上添加long press,long press 被 delay,按的时间稍长才会开始,移动是被drag interactgion cancelled.
- Adding to a Drag
func dragInteraction(_ interaction: UIDragInteraction, itemsForAddingTo session: UIDragSession, withTouchAt point: CGPoint) -> [UIDragItem] {
// Returning 0 items allows normal touch processing to continue
return []
}