import UIKit
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//SwipeGestureRecognizer:滑动手势
let swipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeUp(_ :)))
//设置监听滑动的方向为向上
swipe.direction = .up
//添加到视图中
self.view.addGestureRecognizer(swipe)
//ScreenEdgePanGestureRecognizer:边缘滑动(是UISwipeGestureRecognizer的子类)
let edgeSwipe = UIScreenEdgePanGestureRecognizer(target: self, action:#selector(ViewController.edgeSwipe))
//设置监听滑动的方向
edgeSwipe.edges = .left//从左边缘往右滑
self.view.addGestureRecognizer(edgeSwipe)
//UITapGestureRecognizer:轻击手势
//单击监听
let tapSingle=UITapGestureRecognizer(target:self,action:#selector(Tap(_:)
Swift - UIGestureRecognizer
本文详细探讨了Swift中UIGestureRecognizer的使用,包括各种手势类型如Tap、Pan、Swipe、Pinch和Rotation的实现,以及如何自定义手势识别器,同时讲解了手势之间的冲突解决策略和在实际应用中的最佳实践。
摘要由CSDN通过智能技术生成