UITapGestureRecognizer

Configuring the Gesture

@property(nonatomic) NSUInteger numberOfTapsRequired
@property(nonatomic) NSUInteger numberOfTouchesRequired

例子

    // 单击的 Recognizer
    UITapGestureRecognizer* singleRecognizer;
    singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(SingleTap:)];
    //点击的次数
    singleRecognizer.numberOfTapsRequired = 1; // 单击
    [self.view addGestureRecognizer:singleRecognizer];

    // 双击的 Recognizer
    UITapGestureRecognizer* doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(DoubleTap:)];
    doubleRecognizer.numberOfTapsRequired = 2; // 双击
    //关键语句,给self.view添加一个手势监测;
    [self.view addGestureRecognizer:doubleRecognizer];

    // 关键在这一行,双击手势确定监测失败才会触发单击手势的相应操作
    [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
    [singleRecognizer release];
    [doubleRecognizer release];
时间: 2024-10-29 19:08:34

UITapGestureRecognizer的相关文章

ios UITapGestureRecognizer 单指单击、单指多击、多指单击、多指多击事件操作

转自:http://blog.csdn.net/longzs/article/details/7457108 在ios开发中,需用到对于手指的不同操作,以手指点击为例:分为单指单击.单指多击.多指单击.多指多击.对于这些事件进行不同的操作处理,由于使用系统自带的方法通过判断touches不太容易处理,而且会有事件之间的冲突. 接下来,通过以UITapGestureRecognizer 手势实现此功能需求 代码如下: ViewController.m中的viewDidLoad方法: 1: //单指

iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效

ViewDidLoad中注册手势的部分代码如下: [cpp] view plaincopy UITapGestureRecognizer *oneTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard)] autorelease]; oneTap.delegate = self; oneTap.numberOfTouchesRequired = 1; [self.view a

UITableView添加UITapGestureRecognizer与didSelectRowAtIndexPath冲突解决方法

在UITableView上添加了UITapGestureRecognizer后会导致didSelectRowAtIndexPath失效,原因是UITapGestureRecognizer会截取了tableView的touch事件,导致无法响应行选择,解决方法是重写UIGestureRecognizerDelegate中的 1 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(

IOS UILabel用UITapGestureRecognizer实现点击事件

点击UILabel跳转页面: //定义UILabel @property (weak, nonatomic) IBOutlet UILabel *nameLabel; 用UITapGestureRecognizer手势触碰实现UILabel的点击事件 UITapGestureRecognizer *tapName = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchHeaderImageView:

UITapGestureRecognizer 的用法

UITapGestureRecognizer 的用法 //单指单击 2: UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self 3: action:@selector(handleSingleFingerEvent:)]; 4: singleFingerOne.numberOfTouchesRequired = 1; //手指数 5: singleFingerOn

UITapGestureRecognizer 获取点击位置

原来我自定义过UITextView,然后将捕获 touchesBegan,touchesMoved和touchesEnded的事件后交给父层去处理,这样就可以UITextView上进行手势翻页 等处理,今天想要故伎重演在UIWebView上,结果失败了.后来用了一种最最简单的办法实现了. 你猜对了,是UITapGestureRecognizer,贴上代码. 在UIViewController中,加入协议UIGestureRecognizerDelegate,然后.m文件里加入以下代码: UITa

iphone练习之手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognizer

首先新建一个基于Sigle view Application的项目,名为GestureTest;我的项目结构如下: 往viewController.xib文件里拖动一个imageView,并使覆盖整个屏幕,改动属性为: viewController.h文件: 1.     #import <UIKit/UIKit.h> 2. 3.     @interface ViewController : UIViewController{ 4.         IBOutlet UIImageView 

iOS 控件点击效果 手势效果 UITapGestureRecognizer用法

在需要给图片,图标等控件添加 点击效果,手势效果的UITapGestureRecognizer用法 直接看代码示例: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,32

UITapGestureRecognizer 手势传值

- (void)setImageArray:(NSArray *)imageArray { self.count = count; // 1.添加图片到scrollView中 for (int i = 0; i < count; i++) { UIImageView *imageView = [[UIImageView alloc] init]; imageView.tag = i; // 传值 imageView.userInteractionEnabled = YES; UITapGestu