首页 > 代码库 > iOS 手势识别器概述

iOS 手势识别器概述

手势识别器

iOS 手势识别器(UIGestureRecognizer)

  • 点击手势(UITapGestureRecognizer)
  • 滑动手势(UISwipeGestureRecognizer)
  • 旋转手势(UIRotationGestureRecognizer)
  • 捏合手势( UIPinchGestureRecognizer)
  • 长按手势( UILongPressGestureRecognizer)
  • 平移手势( UIPanGestureRecognizer)
  • 屏幕边缘平移手势(UIScreenEdgePanGestureRecognizer)

UIGestureRecognizer

其相应的方法:

- initWithTarget:action:
- addTarget:action:
- removeTarget:action:
- locationInView:
- locationOfTouch:inView:
- numberOfTouches

属性:

  • stated
  • view
  • enable
  • cancelsTouchesInView
  • delaysTouchesBegin


    这里有一个方法,很重要,当你须要使用双击手势时,单击手势也会出现.这个时候就要使用以下的方法:

 - requireGestureRecognizerToFail:(eg: 单击须要双击失败)

UITapGestureRecognizer

  • numberofTapsRequired (点击的次数)
  • numberOfTouchesRequired (用的是几根手指)

UISwipeGestureRecognizer

  • direction (移动的方向)
  • numberOfTouchesRequired

UIRotationGestureRecognizer

  • rotation (这里是旋转角度的绝对值,不是增量值,假设须要增量值,须要每次 rotation 置 0)
  • velocity (每秒多少弧长, radius 为 1 )

UIPinchGestureRecognizer

  • scale (假设 须要获得增量值,也须要 scale 置 1)
  • velocity (每秒多少 scale)

UILongPressGestureRecognizer

  • minimumPressDuration
  • numberOfTouchesRequired
  • numberOfTapsRequired
  • alowableMovement(同意移动)

UIPanGestureRecognizer

  • maximumNumberOfTouches
  • minimumNumberOfTouches

- translationinView:
- setTranslation:inView:
- velocityView:  (速度以 CGpoint 方式返回,能够分解为 x 和 y 两个方向的速度 )

UIScreenEdgePanGestureRecognizer

  • edges

>
这个手势与平移手势有些不同,它是以屏幕边缘的部分才干产生效果,一般使用时须要特殊处理,否则就会与平移手势产生冲突.由于它继承 UIPanGestureRecognizer


<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

iOS 手势识别器概述