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

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

 对于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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值