手势识别器(UIImageView)
来源:互联网 发布:手机视频文件加密软件 编辑:程序博客网 时间:2024/06/06 09:37
//1** UIImageView
UIImage *image=[UIImageimageNamed:@"a944621500d792503e95f7077dec376b.jpg"];
self.imageView=[[UIImageViewalloc]initWithImage:image];
self.imageView.frame=CGRectMake(50,100,200, 200);
[self.viewaddSubview:self.imageView];
[_imageView release];
//把图片的用户交互打开,它默认是关闭的,此外还有一个控件是label
self.imageView.userInteractionEnabled=YES;
//1.点击
UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapAction:)];
//设置点击几次才会触发方法
tap.numberOfTapsRequired=2;
//设置几根手指进行点击
tap.numberOfTouchesRequired=2;
//将手势添加到对应的图片上
[self.imageViewaddGestureRecognizer:tap];
[taprelease];
#pragma mark 点击的方法
-(void)tapAction:(UITapGestureRecognizer *)tap
{
NSLog(@"测试点击手势");
self.imageView.image=[UIImageimageNamed:@"a5bcfced872ff6cf7661b9005ba57922.jpeg"];
}
//2.长按(常用)
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPressAction:)];
//设置长按触发的最小时间
longPress.minimumPressDuration=2;
//允许用户手指在长按过程中允许移动的距离
longPress.allowableMovement=200;
//把手势添加到图片上
[self.imageViewaddGestureRecognizer:longPress];
[longPressrelease];
#pragma mark 长按对应的响应方法
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{ //长按的状态
//长按弹一个UIAlertView
if (self.alertview ==nil) {
self.alertview =[[UIAlertViewalloc]initWithTitle:@"hello world"message:@"*_*"delegate:selfcancelButtonTitle:@"YES"otherButtonTitles:@"NO",nil];
[self.alertviewshow];
[self.alertviewrelease];
}else{
[self.alertviewshow];
}
}
//3.旋转
//创建一个旋转的手势
UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotationAction:)];
//把手势放到对应的图片上
[self.imageViewaddGestureRecognizer:rotation];
//释放
[rotationrelease];
#pragma mark 旋转对应的响应方法
-(void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
//可以通过手势获取手势添加的视图是哪一个
UIImageView *imageView=(UIImageView *)rotation.view;
//进行旋转的操作
//通过视图的transform属性,让视图进行旋转
//imageView.transform=CGAffineTransformMakeRotation(rotation.rotation);
imageView.transform=CGAffineTransformRotate(imageView.transform, rotation.rotation);
rotation.rotation=0;
}
//创建
UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinchAction:)];
//添加到图片上
[self.imageViewaddGestureRecognizer:pinch];
//释放
[pinchrelease];
#pragma mark捏合对应的响应方法(缩放图片)
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch{
//通过手势找视图
UIImageView *imageView=(UIImageView *)pinch.view;
//通过transform改变图片的尺寸
//第一个参数是原来图片的大小,第二和第三个参数是相对于x轴,y轴的缩放比例
imageView.transform=CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
//为了防止手势的变化让图片直接消失
pinch.scale=1;
}
//5.拖拽
//创建
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panAction:)];
[self.imageViewaddGestureRecognizer:pan];
[panrelease];
-(void)panAction:(UIPanGestureRecognizer *)pan
{
//通过手势找视图
UIImageView *imageView=(UIImageView *)pan.view;
//通过手势获得经过的点
CGPoint p=[pantranslationInView:imageView];
//设置移动的位置
imageView.transform=CGAffineTransformTranslate(imageView.transform, p.x, p.y);
//为了防止手势在操作的时候视图消失
[pansetTranslation:CGPointZeroinView:imageView];
}
//6.轻扫
UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipeAction:)];
[self.imageViewaddGestureRecognizer:swipe];
[swiperelease];
//轻扫的方向,向右
swipe.direction =UISwipeGestureRecognizerDirectionRight;
#pragma mark 轻扫的对应方法
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{
if (swipe.direction ==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"向右");
}
}
- 手势识别器(UIImageView)
- iOS编程-------UIImageView、手势识别器UIGestureRecognizer
- iOS- UIImageView/手势识别
- UIImage与UIImageView属性总结以及手势识别器
- UI一揽子计划 5 (Target: Action: 、Protocol Delegate、 UIImageView 、手势识别器)
- 07 手势识别器、UIImageView、(transform)、模拟button内部实现触摸事件
- 手势识别(一)手势识别器
- 手势识别器
- 手势识别器
- 33.手势识别器
- UI_GestureRecognizer_手势识别器
- UI04手势识别器
- 手势识别器(敲击)
- android手势识别器
- 手势识别器
- UIGestureRecognizer(手势识别器)
- 44.手势识别器
- 手势识别器
- ContextClassLoader
- 8月2日----TCP Socket 编程
- thread safe lazy initialization singleton
- 啊哈,算法! -----dfs1
- 2100 Seeding【dfs】
- 手势识别器(UIImageView)
- !HDU 4346 插旗子RGR的插法有多少种-思维&正难则逆&思维!
- Ubuntu下nginx的编译与安装
- 计算机网络面试题
- JSP中页面跳转response.sendRedirect()和request.getRequestDispatcher()的区别
- Codeforces 4B
- FreeBSD 下 MySQL 安装与基本维护
- 最简单通用加载效果---完全实现自定义
- POJ2139--Six Degrees of Cowvin Bacon