iOS 点击手势等响应区域探讨

xiaoxiao2021-02-28  75

 #超出响应区域无法响应相关的事件

 对于iOS的点击事件来说如果点击的区域超出了其本身的视图大小和其父视图的大小,是不会响应这个点击事件的,这个特性对于UIControl, UIButton, UITapGestureRecognizer, UILongPressGestureRecognizer, UISwipeGestureRecognizer等响应点击事件的控件或手势来说是很重要的,只要控件或手势超出了其本身的大小和其父视图的大小,那就不会响应点击事件。

 

 #超出响应区域仍能继续响应相关的事件

 但是对于滑动手势如:UIPanGestureRecognizer, UIRotationGestureRecognizer, UIPinchGestureRecognizer手势来说超出其本身大小和其父视图的大小后仍能响应滑动事件。

// // ViewController.m // test_panGesture_01 // // Created by jeffasd on 2017/7/10. // Copyright © 2017年 jeffasd. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController /** #超出响应区域无法响应相关的事件 对于iOS的点击事件来说如果点击的区域超出了其本身的视图大小和其父视图的大小,是不会响应这个点击事件的,这个特性对于UIControl, UIButton, UITapGestureRecognizer, UILongPressGestureRecognizer, UISwipeGestureRecognizer等响应点击事件的控件或手势来说是很重要的,只要控件或手势超出了其本身的大小和其父视图的大小,那就不会响应点击事件。 #超出响应区域仍能继续响应相关的事件 但是对于滑动手势如:UIPanGestureRecognizer, UIRotationGestureRecognizer, UIPinchGestureRecognizer手势来说超出其本身大小和其父视图的大小后仍能响应滑动事件。 */ - (void)viewDidLoad { [super viewDidLoad]; UIView *panGestureView = [UIView new]; panGestureView.backgroundColor = [UIColor cyanColor]; [self.view addSubview:panGestureView]; CGRect frame = (CGRect){100, 100, 200, 200}; panGestureView.frame = frame; //UITapGestureRecognizer //UILongPressGestureRecognizer //UISwipeGestureRecognizer //UIPanGestureRecognizer //UIRotationGestureRecognizer //UIPinchGestureRecognizer UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)]; [panGestureView addGestureRecognizer:panGesture]; } - (void)panGesture:(UIGestureRecognizer *)gesture{ CGPoint point = [gesture locationInView:gesture.view]; NSLog(@"point is %@", NSStringFromCGPoint(point)); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

转载请注明原文地址: https://www.6miu.com/read-32430.html

最新回复(0)