- (void)viewDidLoad
{
[super viewDidLoad];
_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 30)];
_label.textAlignment = NSTextAlignmentCenter;
_label.backgroundColor = [UIColor whiteColor];
_label.textColor = [UIColor redColor];
_label.text = @"捏合手势";
[self.view addSubview:_label];
UIView *gestureView = [[UIView alloc] initWithFrame:CGRectMake(0, 60, 320, 410)];
gestureView.backgroundColor = [UIColor greenColor];
[self.view addSubview:gestureView];
//------------------------捏合手势------------------------
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1Action:)];
//连续点击的数量
tap1.numberOfTapsRequired = 1;
//设置手指点击的数量
// tap1.numberOfTapsRequired = 2;
[gestureView addGestureRecognizer:tap1];
[tap1 release];
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2Action:)];
//连续点击的数量
tap2.numberOfTapsRequired = 2;
[gestureView addGestureRecognizer:tap2];
[tap2 release];
//假如tap1与tap2两个手势都触发,则取消tap1手势
[tap1 requireGestureRecognizerToFail:tap2];
//--------------------轻扫手势-------------------------
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//设置轻扫的方向
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[gestureView addGestureRecognizer:swipe];
[swipe release];
//--------------------移动手势----------------------------
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAtion:)];
[gestureView addGestureRecognizer:pan];
[pan release];
//-------------------长按手势--------------------------------
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longAction:)];
[gestureView addGestureRecognizer:longPress];
[longPress release];
//------------------旋转手势----------------------------------
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAtion:)];
[gestureView addGestureRecognizer:rotation];
[rotation release];
//-----------------捏合手势----------------------------
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
[gestureView addGestureRecognizer:pinch];
[pinch release];
}
- (void)tap1Action:(UITapGestureRecognizer *)tap
{
NSLog(@"单机");
_label.text = @"单机";
}
- (void)tap2Action:(UITapGestureRecognizer *)tap
{
NSLog(@"双机");
_label.text = @"双机";
}
- (void)swipeAction:(UITapGestureRecognizer *)swip
{
NSLog(@"轻扫");
_label.text = @"轻扫";
}
- (void)panAtion:(UITapGestureRecognizer *)pan
{
NSLog(@"移动");
_label.text = @"移动";
}
- (void)longAction:(UITapGestureRecognizer *)pan
{
NSLog(@"长按");
_label.text = @"长按";
}
- (void)rotationAtion:(UITapGestureRecognizer *)pan
{
NSLog(@"旋转");
_label.text = @"旋转";
}
- (void)pinchAction:(UITapGestureRecognizer *)pan
{
NSLog(@"捏合");
_label.text = @"捏合";
}