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.


    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 []
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容