iOS学习笔记27-手势1
-(void)pinchGesture
{
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[self.view addGestureRecognizer:pinch];
}
-(void)pinch:(UIPinchGestureRecognizer *)pinch{
float scale = pinch.scale;
pinch.view.transform = CGAffineTransformScale(pinch.view.transform, scale, scale);
if (scale >1) {
self.gestureLabel.text =@"啮合放大";
}else{
self.gestureLabel.text = @"缩小";
}
}
-(void)addTapGesture
{
/**
*一个手指单击
**/
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tap:)];
tap.numberOfTouchesRequired = 1;
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
/**
*一个手指双击
**/
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
tap2.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tap2];
/**
*手势识别的互斥属性
**/
//当单击和双击同时出现在同一个视图上时,只能实现一个
[tap requireGestureRecognizerToFail:tap2];
/**
*两个手指单击
**/
UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTwoTap:)];
tap3.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:tap3];
[tap2 requireGestureRecognizerToFail:tap3];
}
-(void)swipeGesture
{
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipe];
}
-(void)swipe:(UISwipeGestureRecognizer *)swipe
{
self.gestureLabel.text = @"下清扫";
}
-(void)singleTwoTap:(UITapGestureRecognizer *)tap
{
self.gestureLabel.text = @"两个手指单击";
}
-(void)doubleTap:(UITapGestureRecognizer *)tap
{
self.gestureLabel.text = @"一个手指双击";
}
-(void)Tap:(UITapGestureRecognizer *)tap{
self.gestureLabel.text = @"一个手指单击";
}