{ ui
[super viewDidLoad]; spa
// Do any additional setup after loading the view, typically from a nib. orm
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; ip
[btn setFrame:CGRectMake(50, 50, 100, 100)]; get
[btn setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal]; it
// 拖移的 Recognizer io
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)]; require
[btn addGestureRecognizer:panGestureRecognizer]; select
UIView *tapView = [[UIView alloc] initWithFrame:CGRectMake(10, 50, 300, 300)]; im
[tapView setBackgroundColor:[UIColor redColor]];
// 单击的 Recognizer
UITapGestureRecognizer* singleRecognizer;
singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTap:)];
//点击的次数
singleRecognizer.numberOfTapsRequired = 1; // 单击
//点击的手指数
singleRecognizer.numberOfTouchesRequired = 2;
//给view添加一个手势监测;
[tapView addGestureRecognizer:singleRecognizer];
// 双击的 Recognizer
UITapGestureRecognizer* doubleRecognizer;
doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTap:)];
doubleRecognizer.numberOfTapsRequired = 2; // 双击
//关键语句,给self.view添加一个手势监测;
[tapView addGestureRecognizer:doubleRecognizer];
// 关键在这一行,双击手势肯定监测失败才会触发单击手势的相应操做
[singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
// 捏合的 Recognizer
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[tapView addGestureRecognizer:pinchGestureRecognizer];
// 旋转的 Recognizer
UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotate:)];
[tapView addGestureRecognizer:rotateRecognizer];
// 长按的 Recognizer
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
//设置长按时间间隔
[longPressRecognizer setMinimumPressDuration:1.0];
[tapView addGestureRecognizer:longPressRecognizer];
// 滑动的 Recognizer
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
//设置滑动方向
[swipeRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
[tapView addGestureRecognizer:swipeRecognizer];
[self.view addSubview:tapView];
[self.view addSubview:btn];
}