Men的博客

欢迎光临!

0%

手势

轻击手势Tap

UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dealTap:)];
[_imageView addGestureRecognizer:tap];

}
-(void)dealTap:(UITapGestureRecognizer *)tap
{
NSLog(@”被点击了”);
}

缩放手势Pinch

UIPinchGestureRecognizer *pain=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(dealPinch:)];
[_imageView addGestureRecognizer:pain];
}
-(void)dealPinch:(UIPinchGestureRecognizer *)pinch
{
有一个非常重要的控件 ,缩放系数。pinch.scale
NSLog(@”缩放”);
仿射变换(改变view的位置大小)
_imageView.transform=CGAffineTransformMakeScale(pinch.scale, pinch.scale);
}

旋转手势Rotation

UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(dealrotation:)];
[_imageView addGestureRecognizer:rotation];

}
-(void)dealrotation:(UIRotationGestureRecognizer *)ro
{
重要属性。。rotation.rotation表示旋转角度
_imageView.transform=CGAffineTransformMakeRotation(ro.rotation);
}

滑动手势Swipe

UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(dealSwipe:)];
[_imageView addGestureRecognizer:swipe];
}
-(void)dealSwipe:(UISwipeGestureRecognizer *)swipe
{
NSLog(@”滑动”);
注意:滑动默认的方向是向右
swipe.direction=UISwipeGestureRecognizerDirectionRight;
static int index=0;
NSArray *array=@[@”1173.jpg”,@”1092.jpg”];
index++;
if(index>array.count-1)
{
index=0;
}
_imageView.image=[UIImage imageNamed:array[index]];
// if(index ==0)
// {
// _imageView.image=[UIImage imageNamed:@”1173.jpg”];
// index=1;
// }
// else
// {
// _imageView.image=[UIImage imageNamed:@”1092.jpg”];
// index=0;
// }
}

拖移手势Pan

UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(dealPan:)];
[_imageView addGestureRecognizer:pan];
}
-(void)dealPan:(UIPanGestureRecognizer *)pan
{
重要的属性locationInView
CGPoint point=[pan locationInView:self.view];
_imageView.center=point;
}
长按手势LongPress
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(dealLongPress:)];
[_imageView addGestureRecognizer:longPress];

}
-(void)dealLongPress:(UILongPressGestureRecognizer *)longPress
{
NSLog(@”长按”);
重要的属性 longPress.state
if(longPress.state==UIGestureRecognizerStateBegan)
{
UIAlertView *al=[[UIAlertView alloc]init];
al.message=@”是否保存图片”;
[al addButtonWithTitle:@”取消”];
[al show];
}

}