UI 6大手势

1.轻拍手势

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

[myView addGestureRecognizer:tap];

[tap release];

tap.numberOfTapsRequired = 2;  // 设置点击次数(双击)

tap.numberOfTouchesRequired = 2; // 设置需要手指数

2.轻扫手势

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe)];

[myView addGestureRecognizer:swipe];

[swipe release];

swipe.direction = UISwipeGestureRecognizerDirectionUp; // 设置轻扫方向

3.长按手势

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress)];

[myView addGestureRecognizer:longPress];

[longPress release];

longPress.minimumPressDuration = 2;   // 设置长按时间

4.平移手势

UIPanGestureRecognizer*pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan)];

[myView addGestureRecognizer:pan];

[pan release];

- (void)panAction:(UIPanGestureRecognizer *)pan{

CGPointpoint = [pan translationInView:pan.view];

// transform是视图的一个重要属性我们的平移旋转缩放改变的都是视图的transform属性我们用何种方法去改变他取决于赋值符号右边调用的api

//我们之后学习的动画有很多API都是跟transform有关的

//平移手势在做这个动作时相当于实时地触发这个方法我们每一次的平移都会在上一次平移的基础上继续平移相当于每一次新的值都会再次变为老的值

pan.view.transform=CGAffineTransformTranslate(pan.view.transform, point.x, point.y);

[pan setTranslation:CGPointZero inView:pan.view]; //重新置成0点

}

5.缩放手势

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch)];

[myView addGestureRecognizer:pinch];

[pinch release];

-(void)pinch:(UIPinchGestureRecognizer*)pinch{

pinch.view.transform=CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);

pinch.scale = 1;

}

6.旋转手势

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

[myView addGestureRecognizer:rotation];

[rotation release];

-(void)rotation:(UIRotationGestureRecognizer*)rotation{

//下一次的旋转都会根据上一次的旋转继续旋转

rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);

rotation.rotation=0;

}

手势部分的笔记: 

        UIImageView是用来展示图片的   系统没有给我们提供addTarget action方法所以我们想让UIImageView可以点击需要给其加手势

         手势一根分为七大种每一个手势的类都是继承于UIGestureRecognizer我们操作的时候是操作其子类(边界手势本文没有写)

         一个手势只能添加到一个视图上如果添加到多个视图上只是最后添加的那个视图才会拥有这个手势

        当我们想要操作ImageView时    需要将其交互打开(默认是关闭的)  交互打开的代码如下imageView.userInteractionEnabled = YES;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...
    dliys阅读 406评论 0 1
  • Gesture Recognizer 以前想监听一个view上面的触摸事件,之前的做法是 1 ->自定义一个vie...
    iOS_Cqlee阅读 709评论 0 1
  • - (void)viewDidLoad { [super viewDidLoad]; // Do any addi...
    焦六金Jxx阅读 351评论 0 0
  • UI总结-手势 常用的6种手势: #import "ViewController.h" @...
    Dear丶Musk阅读 490评论 0 0
  • 心无山水难思画,身付春秋始问诗;耄耋初心何处是,白转黑回两归一。 外一篇 从小愚同学那里偶然得知,《内美静中参——...
    林宏海阅读 539评论 0 0