Modern User Interaction on iOS

System Gesture Interaction

  1. tap, pinch, rotate, long press 与 system gesture recognizer同时进行
  2. pan, swipe 在 system gesture recognizer 之后进行
  3. 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

  1. 添加 drag interaction 到 view 的interaction array,drag interaction 创建一些 gesture recognizers 添加到view上,并将自己设置为gesture recognizers 的delegate.
  2. 在View上添加long press,long press 被 delay,按的时间稍长才会开始,移动是被drag interactgion cancelled.


    Modern User Interaction on iOS_第1张图片
    f15097f5-56ba-440a-a6cf-d1a7a6bb6d5f.png
  3. 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 []
}

你可能感兴趣的:(Modern User Interaction on iOS)