iOS-给视图添加手势

轻拍手势

创建一个轻拍手势 同时绑定了一个事件

UITagpGestureRecognizer *aTapGR = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(tapGRAction:)];

设置轻拍次数

aTapGR.numberOfTapsRequired = 1;

设置手指触摸的个数

aTapGR.numberOfTouchesRequired = 2;

添加手势

[self.rootView addGestureRecognizer:aTapGR];
[aTapGR release];

长按手势

UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget: self action:@selector(longPressAction:)];

[self.rootView addGestureRecognizer:longPressGR];
[longPressGR release];

旋转手势

UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
[self.rootView.testImageView addGestureRecognizer:rotationGR];
[rotationGR release];

捏合手势

UIPinchGestureRecognizer *pinchRG = [[UIPinchGestureRecognizer alloc] initWithTarget: self.action:@selector(pinchAction:)];
[self.rootView addGestureRecognizer:pinchRG];
[rotationGR release];

平移手势

UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGRAction:)];
[self.rootView.testImageView addGestureRecognizer:panGR];
[panGR release];

轻扫手势

UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGRAction:)];

设置滑动方向


swipeGR.direction = UISwipeGestureRecognizerDirectionLeft; // 设置向左滑动 
[self.rootView.testImageView addGestureRecognizer:swipeGR];
[swipeGR release];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容