iOS 添加手势
来源:互联网 发布:淘宝买vpn搜什么 编辑:程序博客网 时间:2024/06/07 11:18
给图片添加是需要打开用户交互self.imageView.userInteractionEnabled=YES;1.点击 UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];(1)设置点击几次才会触发 tap.numberOfTapsRequired=2;(2)设置几个手指进行点击 tap.numberOfTouchesRequired=2;(3)将手势添加到对应的图片上 [self.imageview addGestureRecognizer:tap]; [tap release]; (4)实现- (void)tapAction:(UITapGestureRecognizer *)tap{ NSLog(@"测试点击手势”);}2.长按 UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];(1)设置长按触发的最小时间 longPress.minimumPressDuration=2;(2)用户手指在长按过程中允许的移动距离 longPress.allowableMovement=200;(3)把手势添加到图片上 [self.view addGestureRecognizer:longPress]; [longPress release];(4)实现- (void)longPressAction:(UILongPressGestureRecognizer *)longPress{NSLog(@"测试点击手势”);}3.旋转(1)创建一个旋转手势 UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];(2)把手势放到图片上 [self.imageview addGestureRecognizer:rotation];(3)释放 [rotation release]; (4)实现-(void)rotation:(UIRotationGestureRecognizer *)rotation{ //可以通过手势获取手势添加的视图是哪一个..UIImageView *imageView=(UIImageView *)rotation.view; //进行旋转的操作 //通过视图的transform属性让视图进行旋转imageView.transform=CGAffineTransformRotate(imageView.transform, rotation.rotation); rotation.rotation=0;}4.捏合(1)创建 UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];(2)把手势放到图片上 [self.imageview addGestureRecognizer:pinch];(3)释放 [pinch release];(4)实现-(void)pinchAction:(UIPinchGestureRecognizer*)pinch{//根据手势找视图 UIImageView *imageView=(UIImageView *)pinch.view;//通过transform改变图片的尺寸 imageView.transform=CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale); pinch.scale=1;}5.拖拽(1)创建 UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];(2)把手势放到图片上 [self.imageview addGestureRecognizer:pan];(3)释放 [pan release];(4)实现- (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];}6.轻扫(1)创建 UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];(2)把手势放到图片上 [self.imageview addGestureRecognizer:swipe];(3)释放 [swipe release]; //轻扫的方向 swipe.direction = UISwipeGestureRecognizerDirectionRight;(4)实现- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{ if (swipe.direction==UISwipeGestureRecognizerDirectionRight) { NSLog(@"向右"); }}
0 0
- ios添加滑动手势
- IOS-滑动手势添加
- iOS 添加手势
- 添加手势iOS
- IOS添加滑动手势
- iOS手势相关添加
- ios开发中的手势添加
- ios的手势的添加
- iOS-为试图添加手势
- iOS中手势的添加
- iOS开发中的手势添加
- iOS 给手势添加tag
- iOS - UITableViewCell 添加长按手势(别的手势类似):
- iOS开发——添加手势
- IOS UILabel添加手势,增加点击功能
- ios -- UILabel添加手势,增加点击功能
- IOS UILabel添加手势,增加点击功能
- ios添加的手势传值
- mysql添加外键时报errno: 150错误的解决方法
- 攻城狮开发产品以中国高铁成功为鉴
- Tomcat使用Spring管理对象出现HashMap死循环的问题
- Android隐藏输入法键盘(hideSoftInputFromInputMethod没有效果)
- 服务之非绑定服务
- iOS 添加手势
- android二维码的生成和扫描
- Android手机实时视频监控
- DS-5教程-ARM DS-5 添加新芯片至DS-5调试设备列表
- java 写出和读入 Object对象
- hdu 5531 Rebuild(三分)
- Android开源项目分类汇总
- jquery append appendTo before after insertAfter insertBefore prepend prependTo用法区别
- MySQL安装失败问题解决