一.手势
1.点击
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//设置点击几次才会触发方法
tap.numberOfTapsRequired=2;
//设置几根手指进行点击
//tap.numberOfTouchesRequired=2;
//将手势添加到对应的图片上
[self.imageView addGestureRecognizer:tap];
[tap release];
2.长按UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
//设置长按触发的最小时间
longPress.minimumPressDuration=2;
//允许用户手指在长按过程种允许移动距离
longPress.allowableMovement=200;
//把手势添加到图片上
[self.imageView addGestureRecognizer:longPress];
[longPress release];
//创建一个旋转的手势
UIRotationGestureRecognizer *Rotation=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(RotionAction:)];
//把手势放到对应的图片上
[self.imageView addGestureRecognizer:Rotation];
//释放
[Rotation release];
//4.捏合
//创建
UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
//添加到图片上
[self.imageView addGestureRecognizer:pinch];
//释放
[pinch release];
//5.拖拽
//创建
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
//添加
[self.imageView addGestureRecognizer:pan];
//释放
[pan release];
//6.轻扫
UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
[self.imageView addGestureRecognizer:swipe];
[swipe release];
//轻扫的方向
//向右
swipe.direction=UISwipeGestureRecognizerDirectionRight;
//7.屏幕边际手势,iOS7.0之后出现的手势UIScreenEdgePanGestureRecognizer
//#pragma mark 轻扫的对应方法
- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{
if(swipe.direction==UISwipeGestureRecognizerDirectionRight){
NSLog(@"向右");}
}
#pragma mark 通过拖拽手势,让视图随着手势的移动而移动
- (void)panAction:(UIPanGestureRecognizer *)pan{
//通过手势找视图
UIImageView *imageView=(UIImageView *)pan.view;
//通过手势获得经过的点
CGPoint p=[pan translationInView:imageView];
//设置移动的位置
imageView.transform=CGAffineTransformTranslate(imageView.transform, p.x, p.y);
//为了防止手势在操作的时候视图消失
[pan setTranslation:CGPointZero inView:imageView];
}
//#pragma mark 通过捏合手势,缩放图片.
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch{
//通过手势找视图
UIImageView *imageView=(UIImageView *)pinch.view;
//通过transform改变图片的尺寸
imageView.transform=CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
pinch.scale=1;
}
#pragma mark 通过图片的旋转手势,实现图片旋转方法
- (void)RotionAction:(UIRotationGestureRecognizer *)Rotation{
//可以通过手势获取手势添加的视图是那一个
UIImageView *imageView=(UIImageView *)Rotation.view;
//进行旋转的操作
//通过视图的transform属性,让视图进行旋转
imageView.transform=CGAffineTransformRotate(imageView.transform, Rotation.rotation);
Rotation.rotation=0;
}
#pragma mark 点击方法
- (void)tapAction:(UITapGestureRecognizer *)tap;
{
self.imageView.image=[UIImage imageNamed:@"160.jpg"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark 长按对应的响应方法
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress{
//长按的状态
// longPress.state;
//长按之后弹出一个UIAlterView
if (self.alter==nil) {
self.alter=[[UIAlertView alloc] initWithTitle:@"消息提醒" message:@"恩恩" delegate:self cancelButtonTitle:@"cancle" otherButtonTitles:@"2",nil];
[self.alter show];
[_alter release];
self.alter=nil;
}}