// 手势 iOS系统支持七种手势类型
// UIGestureRecognizer 是手势类,他是一个抽象类,我们一般不用它来进行实例化和使用,二十用它的子类
// 1、轻拍手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
// 添加手势
[self.view addGestureRecognizer:tap];
[self.myLabel addGestureRecognizer:tap];
[tap release];
// 需要轻拍的次数
tap.numberOfTapsRequired = 2;
// 需要几个手指
tap.numberOfTouchesRequired = 2;
// 2、长按手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longAction:)];
[self.myLabel addGestureRecognizer:longPress];
// 长按次数
longPress.minimumPressDuration = 2;
[longPress release];
// 3、旋转手势
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
[self.myLabel addGestureRecognizer:rotationGesture];
[rotationGesture release];
// 4、轻扫手势 默认是从左往右扫
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.myLabel addGestureRecognizer:swipeGesture];
[swipeGesture release];
iOS学习-手势
最新推荐文章于 2023-07-31 15:42:18 发布