iOS 手势类 : UIGestureRecognizer(继承于NSObject基类)
继承于UIGestureRecognizer类的有六个子类,分别是:
UILongPressGestureRecognizer
UIPanGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UITapGestureRecognizer
UISwipeGestureRecognizer
/*第一个子类*/
用到了UISwipeGestureRecognizer,先记录下
它的属性:方向(direction
property),和touch次数(numberOfTouchesRequired
property);
typedef enum { UISwipeGestureRecognizerDirectionRight = 1 << 0, UISwipeGestureRecognizerDirectionLeft = 1 << 1, UISwipeGestureRecognizerDirectionUp = 1 << 2, UISwipeGestureRecognizerDirectionDown = 1 << 3 } UISwipeGestureRecognizerDirection;
- 示例:
UISwipeGestureRecognizer *gestureRight = [[UISwipeGestureRecognizer alloc] init];
//手势的方向
[gestureRight setDirection:UISwipeGestureRecognizerDirectionRight];
//添加事件
[gestureRight addTarget:self action:@selector(gestureRight:)];
//设置触摸次数,默认为1次
gestureRight.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:gestureRight];
-
- (void)gestureRight:(id)sender {
//code there
}
/*第二个子类*/
UIPanGestureRecognizer(与view中的坐标有关)
属性:
-
maximumNumberOfTouches
property -
minimumNumberOfTouches
property - 这个可以使用多个手指
-
-