#import "ViewController.h"@interface ViewController ()@property (nonatomic,retain)UIImageView *imageView;
@property (nonatomic,assign)NSInteger index;//下标
@property (nonatomic,retain)NSMutableArray *images;//图片名    字数组@end@implementation ViewController
#加载视图-(void)viewDidLoad
{[super viewDidLoad];
//布局imageView
[self layoutImageView];
//1.创建轻拍手势
[self tapGestureRecognizer];
//2.创建清扫手势
[self swipeGestureRecognizer];
//3.创建长安手势
[self longPressGestureRecognizer];
//4.创建平移手势
[self panGestureTecognizer];
//5.创建捏合手势
[self pinchGestureRecognizer];
//6.创建 旋转手势
[self rotationGestureRecognizer]
//7.创建边缘手势
[self screenEdgePanGestureRecognizer];
}
##布局ImageView-(void)layoutImageView
{//创建对象
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
//配置属性
imageView.backgroundColor =[UIColor purpleColor];
//设置图片
imageView.image =[UIImage imageNamed:@"car1.jpg"];
//添加父视图
[self.view addSubview:imageView];
//将创建的图片视图对象 给属性赋值
self.imageView =imageView;
//打开用户交互
self.imageView.userInteractionEnabled =YES;
self.images =[NSMutableArray array];
for (int i = 1; i<9; i++) {NSString * imageName =[NSString stringWithFormat:@"car%d.jpg",i];[_images addObject:imageName];
}
// _index =1;}#pragma 轻怕手势
//创建轻拍手势
-(void)tapGestureRecognizer
{//创建手势对象
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self     action:@selector(tapAction:)];
//配置属性
//轻拍次数
tap.numberOfTapsRequired =1;
//轻拍手指个数
tap.numberOfTouchesRequired =1;
//讲手势添加到指定的视图上
[_imageView addGestureRecognizer:tap];}//轻拍事件-(void)tapAction:(UITapGestureRecognizer *)tap
{//图片切换
NSLog(@"拍一下");
_index ++;
if (_index == 8) {_index = 1;
}
self.imageView.image =[UIImage imageNamed:_images[_index]];}
#pragma 清扫手势//清扫手势
-(void)swipeGestureRecognizer
{UISwipeGestureRecognizer *swipe =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
//配置属性
//一个清扫手势  只能有两个方向(上和下) 或者 (左或右)
//如果想支持上下左右清扫  那么一个手势不能实现  需要创建两个手势
swipe.direction =UISwipeGestureRecognizerDirectionLeft;
//添加到指定视图
[_imageView addGestureRecognizer:swipe];
UISwipeGestureRecognizer *swipe2 =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
swipe2.direction =UISwipeGestureRecognizerDirectionRight;
[_imageView addGestureRecognizer:swipe2];}
//清扫事件
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{NSLog(@"扫一下");
if (swipe.direction ==UISwipeGestureRecognizerDirectionRight)       {NSLog(@"右清扫");_index --;if (_index < 1) {_index =7;}_imageView.image =[UIImage imageNamed:_images[_index]];
}else if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){NSLog(@"左扫一下");_index ++;if (_index == 8) {_index=1;}_imageView.image =[UIImage imageNamed:_images[_index]];
}}
#pragma 长按手势
//创建长按手势
-(void)longPressGestureRecognizer
{UILongPressGestureRecognizer *longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
//最短长按时间
longPress.minimumPressDuration =2;
//允许移动最大距离
longPress.allowableMovement =1;
//添加到指定视图
[_imageView addGestureRecognizer:longPress];}
//长按事件
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{//NSLog(@"长按");
//对于长安有开始和 结束状态
if (longPress.state == UIGestureRecognizerStateBegan) {NSLog(@"长按开始");//将图片保存到相册UIImage *image =[UIImage imageNamed:_images[_index]];UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}else if (longPress.state == UIGestureRecognizerStateEnded)
{NSLog(@"长按结束");
}}#pragma 平移手势
//创建平移手势
-(void)panGestureTecognizer
{UIPanGestureRecognizer *pan =[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
//添加到指定视图
[_imageView addGestureRecognizer:pan];}
//创建平移事件
-(void)panAction:(UIPanGestureRecognizer *)pan
{//获取手势的位置
CGPoint position =[pan translationInView:_imageView];//通过stransform 进行平移交换
_imageView.transform = CGAffineTransformTranslate(_imageView.transform, position.x, position.y);
//将增量置为零
[pan setTranslation:CGPointZero inView:_imageView];}#pragma 捏合手势
-(void)pinchGestureRecognizer
{UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
//添加到指定视图
[_imageView addGestureRecognizer:pinch];}
//添加捏合事件
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch
{//通过 transform(改变) 进行视图的视图的捏合
_imageView.transform =CGAffineTransformScale(_imageView.transform, pinch.scale, pinch.scale);
//设置比例 为 1
pinch.scale = 1;}
#pragma 旋转手势//创建旋转手势
-(void)rotationGestureRecognizer
{UIRotationGestureRecognizer *rotation =[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
//添加到指定的视图
[_imageView addGestureRecognizer:rotation];}
//旋转事件-(void)rotationAction:(UIRotationGestureRecognizer *)rote
{//通过transform 进行旋转变换
_imageView.transform = CGAffineTransformRotate(_imageView.transform, rote.rotation);
//将旋转角度 置为 0
rote.rotation = 0;}
#pragma 边缘手势//创建边缘手势
-(void)screenEdgePanGestureRecognizer
{UIScreenEdgePanGestureRecognizer *screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPanAction:)];
[_imageView addGestureRecognizer:screenPan];}
//创建边缘事件
-(void)screenPanAction:(UIScreenEdgePanGestureRecognizer *)screenPan
{NSLog(@"边缘");}- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}@end
}

IOS - 七大手势操作相关推荐

  1. 【iOS】--手势操作

    文章目录 UIGestureRecognizer 的继承关系: 使用手势步骤 UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(拖动) UIRot ...

  2. iOS手势操作简介(一)

    iOS中能够响应手势操作的类必须要继承自UIResponder,才能够处理手势响应操作. 默认继承了UIResponder的类有:UIApplication UIViewController UIVi ...

  3. ios pan手势滑动消失动画_解析Color OS全面屏手势,操作丝滑,操作逻辑帮了大忙...

    安卓手机真的越来越流畅了!这是我在重度使用OPPO Reno4一段时间后得到的结论. 在使用手机时,我们对手机体验的感知首先就来自于系统.而其中,手机使用是否顺手,反应是否快的第一表现,就是手机操作上 ...

  4. iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义

    http://www.cnblogs.com/huangjianwu/p/4675648.html 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动 ...

  5. iOS——6种系统手势操作

    UIGestureRecognizer(手势识别器) 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了六种常用的手势(UIGestureRe ...

  6. iOS开发系列课程(08) --- 事件处理详解和手势操作

    iOS中的事件分发 事件的分类 Touch Events(多点触摸事件) touchesBegan:withEvent:方法:一个或多个手指置于视图或窗口上 touchesMoved:withEven ...

  7. iOS手势操作简介(五)

    利用手势操作实现抽屉效果: 第一步:搭建UI (void)addChildView { // left UIView *leftView = [[UIView alloc] initWithFrame ...

  8. iphonex如何关机_iphonex常用手势操作有哪些 iphonex常用手势操作介绍【详解】

    iphonex常用手势操作有什么?相信小伙伴们一定很好奇,下面小编为大家带来了iphonex常用手势操作大全一览,感兴趣的小伙伴赶紧跟着小编一起来看看吧. 如何唤醒Siri 苹果一直追求极简的设计思路 ...

  9. 《移动App测试的22条军规》—App测试综合案例分析23.4节测试微信App的手势操作...

    本节书摘来自异步社区<移动App测试的22条军规>一书中的App测试综合案例分析,第23.4节测试微信App的手势操作,作者黄勇,更多章节内容可以访问云栖社区"异步社区" ...

最新文章

  1. 封装一个计时器,记录页面的停留时间
  2. 设计模式我学过呀,就是没用过
  3. R语言双因素方差分析
  4. 技术总监到底要不要写代码?
  5. MVC 使用自定义HtmlHelper截断文本内容
  6. 导出oracle awr分析报告,配置oracle内存参数,察看表空间使用率
  7. 源码级别的广播与监听实现
  8. (c语言)将一个数组逆序输出
  9. linux定时任务cron配置
  10. 新旧 iPhone 比速度,iOS 12 公开测试版发布!
  11. 图像形状特征(八)--SC形状上下文
  12. cello 有关状态
  13. 浅议-动态范围控制(DRC)
  14. php仿止伪装ip,php伪造ip与防止伪造ip方法解析
  15. vue element-ui 实现可输入的选择下拉框
  16. 无法打开这个应用,查看Microsoft store, 了解有关Nahimic的详细信息
  17. CUDA PTX ISA阅读笔记(一)
  18. 【PTA-训练day20】L2-032 彩虹瓶 + L1-080 乘法口诀数列
  19. 计算机安全外文文献出处,网络信息安全外文文献翻译中英文.doc
  20. C++静态成员和非静态成员的区别

热门文章

  1. 【Unity3d】在Unity3d中使用百度AI人脸识别功能
  2. Android-蓝牙通信
  3. 【软件逆向-自动化】逆向工具大全
  4. 各种食用油的正确烹饪方法
  5. HDU - 1824 Let's go home
  6. OSPF的三张表(链路状态公告)
  7. linux创建蓝光映像光盘,11.13 mkisofs指令:创建光盘映像文件
  8. 分布式存储系统-Ceph简单分析
  9. 当罗“工匠”遇上雷“铁匠”
  10. 综合素质计算机考点,教师资格综合素质考前必背知识点:基本能力