iOS手势处理

iOS手势有着如下几种:

上面的手势对应的操作是:

  • Tap          (点一下)
  • Pinch        (二指往內或往外拨动,平时经常用到的缩放)  矩阵变换
  • Rotation    (旋转)                                                  矩阵变换
  • Swipe       (滑动,快速移动)
  • Pan          (拖移,慢速移动)                                     矩阵变换
  • LongPress (长按)

注意:以下示例均把手势封装进一个View当中

UITapGestureRecognizer - 点击手势

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
  5. @property (nonatomic, strong) CALayer *colorLayer;
  6. @end
  7.  
  8. @implementation GestureView
  9.  
  10. - (id)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. // 初始化手势,给手势指定响应事件的对象
  14. _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
  15. action:@selector(gestureEvent:)];
  16. _colorLayer = [CALayer layer];
  17. _colorLayer.frame = self.bounds;
  18.  
  19. [self.layer addSublayer:_colorLayer];
  20.  
  21. // 将手势与区域绑定
  22. [self addGestureRecognizer:_tapGesture];
  23. }
  24. return self;
  25. }
  26.  
  27. - (void)gestureEvent:(UIGestureRecognizer *)sender {
  28. _colorLayer.backgroundColor = [UIColor colorWithRed:arc4random() % / .f
  29. green:arc4random() % / .f
  30. blue:arc4random() % / .f
  31. alpha:1.0f].CGColor;
  32. }
  33.  
  34. @end

GestureView.m

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesture recognizer.

将手势识别器附着在一个view上,实际上定义了一个手势接收的区域,会将接收到的触摸事件传递给这个view以及这个view的所有的subviews.这个view会对这个手势识别器强引用.

可以总结两点:

1. 手势会传递给这个view中所有的subviews

2. view会强引用手势识别器

使用如下:

点击手势有两个参数可以设置:

numberOfTapsRequired         点击几次触发事件(默认是1)

numberOfTouchesRequired    需要几个手指点击(默认是1)

UIPinchGestureRecognizer - 缩放

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UIPinchGestureRecognizer *pinchGesture;
  5. @end
  6.  
  7. @implementation GestureView
  8.  
  9. - (id)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self)
  13. {
  14. // 初始化手势,给手势指定响应事件的对象
  15. _pinchGesture = \
  16. [[UIPinchGestureRecognizer alloc] initWithTarget:self
  17. action:@selector(gestureEvent:)];
  18.  
  19. // 将手势与区域绑定
  20. [self addGestureRecognizer:_pinchGesture];
  21. }
  22. return self;
  23. }
  24.  
  25. - (void)gestureEvent:(UIPinchGestureRecognizer *)sender
  26. {
  27. //
  28. self.transform = CGAffineTransformScale(self.transform, sender.scale, sender.scale);
  29. sender.scale = ;
  30. }
  31.  
  32. @end

GestureView.m

缩放手势会用到矩阵变换.

UIRotationGestureRecognizer - 旋转

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UIRotationGestureRecognizer *rotationGesture;
  5. @end
  6.  
  7. @implementation GestureView
  8.  
  9. - (id)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self)
  13. {
  14. // 初始化手势,给手势指定响应事件的对象
  15. _rotationGesture = \
  16. [[UIRotationGestureRecognizer alloc] initWithTarget:self
  17. action:@selector(gestureEvent:)];
  18.  
  19. // 将手势与区域绑定
  20. [self addGestureRecognizer:_rotationGesture];
  21. }
  22. return self;
  23. }
  24.  
  25. - (void)gestureEvent:(UIRotationGestureRecognizer *)sender
  26. {
  27. // 此处用到了矩阵变换
  28. self.transform = CGAffineTransformRotate(self.transform, sender.rotation);
  29. sender.rotation = ;
  30. }

GestureView.m

UISwipeGestureRecognizer - 滑动

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UISwipeGestureRecognizer *swipeGesture;
  5. @end
  6.  
  7. @implementation GestureView
  8.  
  9. - (id)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self)
  13. {
  14. // 初始化手势,给手势指定响应事件的对象
  15. _swipeGesture = \
  16. [[UISwipeGestureRecognizer alloc] initWithTarget:self
  17. action:@selector(gestureEvent:)];
  18. _swipeGesture.direction = \
  19. UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
  20.  
  21. // 将手势与区域绑定
  22. [self addGestureRecognizer:_swipeGesture];
  23. }
  24. return self;
  25. }
  26.  
  27. - (void)gestureEvent:(UISwipeGestureRecognizer *)sender
  28. {
  29. NSLog(@"left or right");
  30. }
  31.  
  32. @end

GestureView.m

UIPanGestureRecognizer - 平移

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
  5. @end
  6.  
  7. @implementation GestureView
  8.  
  9. - (id)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self)
  13. {
  14. // 初始化手势,给手势指定响应事件的对象
  15. _panGesture = \
  16. [[UIPanGestureRecognizer alloc] initWithTarget:self
  17. action:@selector(gestureEvent:)];
  18.  
  19. // 将手势与区域绑定
  20. [self addGestureRecognizer:_panGesture];
  21. }
  22. return self;
  23. }
  24.  
  25. - (void)gestureEvent:(UIPanGestureRecognizer *)sender
  26. {
  27. // 此处用到了矩阵变换
  28. CGPoint translation = [sender translationInView:self];
  29.  
  30. self.center = CGPointMake(self.center.x + translation.x,
  31. self.center.y + translation.y);
  32.  
  33. [sender setTranslation:CGPointZero
  34. inView:self];
  35. }
  36.  
  37. @end

GestureView.m

UILongPressGestureRecognizer - 长按手势

GestureView.h + GestureView.m

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface GestureView : UIView
  4.  
  5. @end

GestureView.h

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UILongPressGestureRecognizer *longPressGesture;
  5. @end
  6.  
  7. @implementation GestureView
  8.  
  9. - (id)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self)
  13. {
  14. // 初始化手势,给手势指定响应事件的对象
  15. _longPressGesture = \
  16. [[UILongPressGestureRecognizer alloc] initWithTarget:self
  17. action:@selector(gestureEvent:)];
  18. _longPressGesture.minimumPressDuration = 2.0f;
  19.  
  20. // 将手势与区域绑定
  21. [self addGestureRecognizer:_longPressGesture];
  22. }
  23. return self;
  24. }
  25.  
  26. - (void)gestureEvent:(UILongPressGestureRecognizer *)sender
  27. {
  28. NSLog(@"触发事件");
  29. }
  30.  
  31. @end

GestureView.m

问题:如何处理一个view中添加了两个手势,1个是单击的手势,一个是双击的手势呢?

可以使用这个方法requireGestureRecognizerToFail:

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4. @property (nonatomic, strong) UITapGestureRecognizer *tapGesture1;
  5. @property (nonatomic, strong) UITapGestureRecognizer *tapGesture2;
  6. @end
  7.  
  8. @implementation GestureView
  9.  
  10. - (id)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. // 单击手势
  14. _tapGesture1 = \
  15. [[UITapGestureRecognizer alloc] initWithTarget:self
  16. action:@selector(gesture1Event:)];
  17. _tapGesture1.numberOfTapsRequired = ;
  18.  
  19. // 双击手势
  20. _tapGesture2 = \
  21. [[UITapGestureRecognizer alloc] initWithTarget:self
  22. action:@selector(gesture2Event:)];
  23. _tapGesture2.numberOfTapsRequired = ;
  24.  
  25. // 注意: 判断双击手势需要时间,也就是说会有延时
  26.  
  27. // 有事件触发时,先判断是不是 双击手势,如果不是就执行 单击手势
  28. [_tapGesture1 requireGestureRecognizerToFail:_tapGesture2];
  29.  
  30. // 将手势与区域绑定
  31. [self addGestureRecognizer:_tapGesture1];
  32. [self addGestureRecognizer:_tapGesture2];
  33. }
  34. return self;
  35. }
  36.  
  37. - (void)gesture1Event:(UIGestureRecognizer *)sender {
  38. NSLog(@"");
  39. }
  40.  
  41. - (void)gesture2Event:(UIGestureRecognizer *)sender {
  42. NSLog(@"");
  43. }
  44.  
  45. @end

GestureView.m

实际上,这种方式会有延时感-_-!!!!

问题:如何将长按手势和拖拽手势合并在一起呢?

我们需要用代理实现,实现以下的方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer  shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.

询问这个代理,是否允许两个手势同时触发.

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()<UIGestureRecognizerDelegate>
  4.  
  5. {
  6. BOOL shouldAllowPan;
  7. }
  8.  
  9. @property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
  10. @property (nonatomic, strong) UILongPressGestureRecognizer *longPressGesture;
  11. @end
  12.  
  13. @implementation GestureView
  14.  
  15. - (id)initWithFrame:(CGRect)frame {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. // 初始化时不允许拖拽
  19. shouldAllowPan = NO;
  20.  
  21. _panGesture = \
  22. [[UIPanGestureRecognizer alloc] initWithTarget:self
  23. action:@selector(panEvent:)];
  24. [self addGestureRecognizer:_panGesture];
  25. _panGesture.delegate = self;
  26.  
  27. _longPressGesture = \
  28. [[UILongPressGestureRecognizer alloc] initWithTarget:self
  29. action:@selector(longPressEvent:)];
  30. _longPressGesture.minimumPressDuration = 1.0f;
  31. [self addGestureRecognizer:_longPressGesture];
  32. _longPressGesture.delegate = self;
  33. }
  34. return self;
  35. }
  36.  
  37. - (void)panEvent:(UIPanGestureRecognizer *)sender {
  38.  
  39. if(shouldAllowPan == YES)
  40. {
  41. // 移动的操作
  42. CGPoint translation = [sender translationInView:self];
  43. self.center = CGPointMake(self.center.x + translation.x,
  44. self.center.y + translation.y);
  45.  
  46. [sender setTranslation:CGPointZero
  47. inView:self];
  48. }
  49. else if(sender.state == UIGestureRecognizerStateEnded || \
  50. sender.state == UIGestureRecognizerStateFailed || \
  51. sender.state == UIGestureRecognizerStateCancelled)
  52. {
  53. shouldAllowPan = NO;
  54. }
  55. }
  56.  
  57. - (void)longPressEvent:(UIGestureRecognizer *)sender
  58. {
  59. // 长按开始
  60. if(UIGestureRecognizerStateBegan == sender.state)
  61. {
  62. NSLog(@"长按开始");
  63. self.backgroundColor = [UIColor redColor];
  64. shouldAllowPan = NO;
  65. }
  66.  
  67. // 长按进行中
  68. if(UIGestureRecognizerStateChanged == sender.state)
  69. {
  70. NSLog(@"长按进行中");
  71. shouldAllowPan = YES;
  72. }
  73.  
  74. // 长按结束
  75. if(UIGestureRecognizerStateEnded == sender.state)
  76. {
  77. NSLog(@"长按结束");
  78. self.backgroundColor = [UIColor blackColor];
  79. shouldAllowPan = NO;
  80. }
  81. }
  82.  
  83. // 是否允许多个手势同时触发
  84. - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
  85. shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
  86. {
  87. // 允许
  88. return YES;
  89. }
  90.  
  91. // 是否允许继续跟踪触摸事件
  92. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  93. {
  94. // 条件满足的手势会被传递进来(如果是移动手势,)
  95. if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && shouldAllowPan == NO)
  96. {
  97. return NO;
  98. }
  99.  
  100. return YES;
  101. }
  102.  
  103. @end

GestureView.m

根据手势状态来识别手势触发事件的全称细节是十分重要的.

问题:如何让一个view的部分区域响应拖拽事件呢?

比方说,我们只需要下面红色线指定的区域响应拖拽事件:

  1. #import "GestureView.h"
  2.  
  3. @interface GestureView ()
  4.  
  5. {
  6.  
  7. BOOL allowPan;
  8.  
  9. }
  10.  
  11. @property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
  12. @end
  13.  
  14. @implementation GestureView
  15.  
  16. - (id)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self)
  20. {
  21. // 初始化时不允许拖拽
  22. allowPan = NO;
  23.  
  24. _panGesture = \
  25. [[UIPanGestureRecognizer alloc] initWithTarget:self
  26. action:@selector(panEvent:)];
  27. [self addGestureRecognizer:_panGesture];
  28. }
  29. return self;
  30. }
  31.  
  32. - (void)panEvent:(UIPanGestureRecognizer *)sender
  33. {
  34. // 获取到当前手势在当前视图坐标中触摸的点
  35. CGPoint point = [sender locationInView:self];
  36.  
  37. // 手势开始时置位(手势事件开始过程中仅仅执行一回)
  38. if (sender.state == UIGestureRecognizerStateBegan)
  39. {
  40. // 设定响应的区域
  41. if (self.bounds.size.height / .f >= point.x && self.bounds.size.width / .f >= point.y)
  42. {
  43. allowPan = YES;
  44. }
  45. }
  46.  
  47. // 手势持续(手势事件开始过程中执行多回)
  48. if (sender.state == UIGestureRecognizerStateChanged && allowPan == YES)
  49. {
  50. // 移动的操作
  51. CGPoint translation = [sender translationInView:self];
  52. self.center = CGPointMake(self.center.x + translation.x,
  53. self.center.y + translation.y);
  54.  
  55. [sender setTranslation:CGPointZero
  56. inView:self];
  57. }
  58.  
  59. // 手势结束后置位(手势事件开始过程中仅仅执行一回)
  60. if (sender.state == UIGestureRecognizerStateEnded)
  61. {
  62. allowPan = NO;
  63. }
  64. }
  65.  
  66. @end

GestureView.m

要实现那个效果,以下方法是核心方法,配合手势的状态使用:

// 获取到当前手势在当前视图坐标中触摸的点
    CGPoint point = [sender locationInView:self];

问题:如何在ViewController中获取到点击的坐标,让一个view跟随触摸点移动呢?

可以使用这几个最原始的处理触摸事件的方法来达到效果.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

  1. #import "RootViewController.h"
  2.  
  3. @interface RootViewController ()
  4.  
  5. {
  6. UIView *_panPoint;
  7. CALayer *_redLayer;
  8. }
  9.  
  10. @end
  11.  
  12. @implementation RootViewController
  13.  
  14. - (void)viewDidLoad
  15. {
  16. [super viewDidLoad];
  17.  
  18. // 初始化view
  19. _panPoint = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  20. _panPoint.layer.cornerRadius = .f;
  21. _panPoint.layer.masksToBounds = YES;
  22. [self.view addSubview:_panPoint];
  23.  
  24. // 初始化一个layer
  25. _redLayer = [CALayer layer];
  26. _redLayer.frame = _panPoint.bounds;
  27. _redLayer.backgroundColor = [UIColor redColor].CGColor;
  28. _redLayer.opacity = .f;
  29. [_panPoint.layer addSublayer:_redLayer];
  30. }
  31.  
  32. // 一次完整的触摸事件中,touchesBegan只执行一回
  33. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  34. {
  35. // 获取触摸点坐标
  36. UITouch *touch = [touches anyObject];
  37. CGPoint touchPoint = [touch locationInView:self.view];
  38.  
  39. _panPoint.center = touchPoint;
  40. _redLayer.opacity = 1.0f;
  41. }
  42.  
  43. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  44. {
  45. // 获取触摸点坐标
  46. UITouch *touch = [touches anyObject];
  47. CGPoint touchPoint = [touch locationInView:self.view];
  48.  
  49. _panPoint.center = touchPoint;
  50. }
  51.  
  52. // 一次完整的触摸事件中,touchesEnded只执行一回
  53. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  54. {
  55. // 获取触摸点坐标
  56. UITouch *touch = [touches anyObject];
  57. CGPoint touchPoint = [touch locationInView:self.view];
  58.  
  59. _panPoint.center = touchPoint;
  60. _redLayer.opacity = 0.0f;
  61. }
  62.  
  63. @end

RootViewController.m

也可以直接使用拖拽手势来实现的,不过不完美

  1. #import "RootViewController.h"
  2.  
  3. @interface RootViewController ()
  4.  
  5. {
  6. UIView *_panPoint;
  7. CALayer *_redLayer;
  8. }
  9.  
  10. @end
  11.  
  12. @implementation RootViewController
  13.  
  14. - (void)viewDidLoad
  15. {
  16. [super viewDidLoad];
  17.  
  18. // 初始化view
  19. _panPoint = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  20. _panPoint.layer.cornerRadius = .f;
  21. _panPoint.layer.masksToBounds = YES;
  22. [self.view addSubview:_panPoint];
  23.  
  24. // 初始化一个layer
  25. _redLayer = [CALayer layer];
  26. _redLayer.frame = _panPoint.bounds;
  27. _redLayer.backgroundColor = [UIColor redColor].CGColor;
  28. _redLayer.opacity = .f;
  29. [_panPoint.layer addSublayer:_redLayer];
  30.  
  31. // 定义手势
  32. UIPanGestureRecognizer *panGesture = \
  33. [[UIPanGestureRecognizer alloc] initWithTarget:self
  34. action:@selector(panGestureEvent:)];
  35. [self.view addGestureRecognizer:panGesture];
  36. }
  37.  
  38. - (void)panGestureEvent:(UIPanGestureRecognizer *)sender
  39. {
  40. CGPoint touchPoint = [sender locationInView:self.view];
  41.  
  42. if (sender.state == UIGestureRecognizerStateBegan)
  43. {
  44. _panPoint.center = touchPoint;
  45. _redLayer.opacity = 1.0f;
  46. }
  47. else if (sender.state == UIGestureRecognizerStateChanged)
  48. {
  49. _panPoint.center = touchPoint;
  50. }
  51. else if (sender.state == UIGestureRecognizerStateEnded)
  52. {
  53. _panPoint.center = touchPoint;
  54. _redLayer.opacity = 0.0f;
  55. }
  56. }
  57.  
  58. @end

RootViewController.m

他们两者的对比关系:

手势处理中核心的地方:

1.  UIGestureRecognizerState非常重要,触发事件时可以直接根据这个状态值来判断事件的发生顺序

2.  处理多手势冲突时,可以使用依赖requireGestureRecognizerToFail:来处理,但效果不好

3.  处理多个手势并发响应的时候,需要实现代理并执行方法,请参考上面的事例

4.  仅仅处理一个view上局部的手势事件,需要用到手势的locationInView:方法,并与UIGestureRecognizerState状态值配合使用

附录:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

这是手势的代理方法,在可以不移除手势的情况下关闭手势的响应,此方法涉及到响应链.

iOS手势处理的更多相关文章

  1. ios手势

    iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小   1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...

  2. iOS手势学习UIGestureRecognizer & cocos2d 手势推荐

    iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer  // 长按UIPanGestur ...

  3. iOS 手势识别器概述

    手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手 ...

  4. swift 实现iOS手势密码、指纹密码、faceID

    本博客包含了如何实现iOS手势密码.指纹密码.faceID全步骤,包括了完整的代码. 先附上demo地址https://github.com/Liuyubao/LYBTouchID,支持swift3. ...

  5. iOS手势解锁、指纹解锁--Swift代码

    一.手势密码 1. 1.1.用UIButton组成手势的节点. 1.2.当手指接触屏幕时,调用重写的 touchesBegan:withEvent方法(在touchesBegan里调用setNeeds ...

  6. IOS 手势-轻点、触摸、手势、事件

    1.概念 手势是从你用一个或多个手指接触屏幕时开始,直到手指离开屏幕为止所发生的所有事件.无论手势持续多长时间,只要一个或多个手指仍在屏幕上,这个手势就存在. 触摸是指把手指放到IOS设备的屏幕上,从 ...

  7. IOS 手势详解

    在IOS中手势可以让用户有很好的体验,因此我们有必要去了解一下手势. (在设置手势是有很多值得注意的地方) *是需要设置为Yes的点击无法响应* *要把手势添加到所需点击的View,否则无法响应* 手 ...

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

    1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...

  9. IOS 手势事件的冲突

    关于手操作需要强调几点: UIImageView默认是不支持交互的,也就是userInteractionEnabled=NO ,因此要接收触摸事件(手势识别),必须设置userInteractionE ...

随机推荐

  1. YAOLEI

    http://www.cnblogs.com/skyblue/p/3356933.html

  2. Mysql——权限管理

    安装Mysql时会自动安装一个名为mysql的数据库.这个数据库下面存储的是权限表. mysql> show databases; +--------------------+ | Databa ...

  3. Golang 知识图谱

  4. 详解REST架构风格

    编辑推荐: 本文来自于segmentfault.com,一起了解REST的内在,认识REST的优势,而不再将它当作是“理所当然” 引言 作为Web开发者,你可能或多或少了解一些REST的知识,甚至已经 ...

  5. Redis--redis集群环境搭建

    1.redis-cluster架构图 Redis 自3.0以后开始支持集群.从上图我们可以看出,redis集群的每个节点之间都进行相互通信,在redis集群中,不存在代理层,即没有固定的入口.redi ...

  6. UA 用户代理

    User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本.CPU 类型.浏览器及版本.浏览器渲染引擎.浏览器语言.浏览器插件等.被广泛用来标识 ...

  7. Javascript数组操作函数总结

    (1) shift  删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4,5]; var b = a.shift(); //a:[2,3,4, ...

  8. JDBC连接数据库的完整实例

    package com.sinovatech.util;   import java.sql.CallableStatement; import java.sql.Connection; import ...

  9. Exception的情况——java基础1

    除数为0等ArithmeticException,是RuntimException的子类.而运行时异常将由运行时系统自动抛出,不需要使用throw语句.Java编译器允许忽略运行时异常,一个方法可以既 ...

  10. SpringBoot集成Jersey

    SpringBoot集成Jersey 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> & ...