zoukankan      html  css  js  c++  java
  • IOS常用手势用法

       target参数指的是给谁用手势,入button,view等

        //1.单击

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

        [self.buttonView addGestureRecognizer:singleTapGR];

      - (void)singleTap:(UITapGestureRecognizer *)tap

      {

          NSLog(@"单击");

      }

     

         //2.双击

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

        doubleTap.numberOfTapsRequired=2;

        [self.buttonView addGestureRecognizer:doubleTap];

        //区别单击双击

        [singleTapGR requireGestureRecognizerToFail:doubleTap];

        

      //双击点击事件

      -(void)doubleTap:(UITapGestureRecognizer *)taggestrue

     {

        NSLog(@"双击");

     }

     

        //3.轻扫

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

        //设置轻扫方向,默认向右

        swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;

        [self.view addGestureRecognizer:swipeGesture];

      //轻扫事件

     -(void)swipe:(UISwipeGestureRecognizer *)swipeGesture

     {

        NSLog(@"轻扫手势");

     }

        

        //4.平移

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

        [self.view addGestureRecognizer:panGesture];

      -(void)pan:(UIPanGestureRecognizer *)pan

      {

          CGPoint point=[pan locationInView:self.view];

          NSLog(@"%@",NSStringFromCGPoint(point));

      }

     

        

        //5.长按

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

        longPressGesture.minimumPressDuration=1;

        [self.buttonView addGestureRecognizer:longPressGesture];

      -(void)longPress:(UILongPressGestureRecognizer *)longPress

      {

          //长按离开时一会调用一次,所以需要设置手势状态

          if(longPress.state==UIGestureRecognizerStateEnded)

          {

              NSLog(@"UIGestureRecognizerStateEnded");

              return;

          }

          NSLog(@"长按超过两秒");

      }

     

     

     

     

     

     

     

     

  • 相关阅读:
    .net winform软件自动更新
    系统升级程序的介绍(转)
    View、ViewGroup (转)
    修改ViewPager调用setCurrentItem时,滑屏的速度
    onSaveInstanceState和onRestoreInstanceState
    onSaveInstanceState(Bundle outState)的调用时机
    如何在Eclipse中查看Android源码或者第三方组件包源码
    MyBatis学习总结(一)——MyBatis快速入门
    ASP.NET提取多层嵌套json数据的方法
    C# 解析 Json数据
  • 原文地址:https://www.cnblogs.com/menchao/p/4825536.html
Copyright © 2011-2022 走看看