首页 > 代码库 > UIView单击手势的添加

UIView单击手势的添加

 

效果图:

 

 

代码:

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.        self.title=@"单击手势的添加";        UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];    parentView.backgroundColor=[UIColor redColor];    [self.view addSubview:parentView];        //单击的手势    UITapGestureRecognizer *tapRecognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];    tapRecognize.numberOfTapsRequired = 1;    tapRecognize.delegate = self;    [tapRecognize setEnabled :YES];    [tapRecognize delaysTouchesBegan];    [tapRecognize cancelsTouchesInView];        [self.view addGestureRecognizer:tapRecognize];}#pragma UIGestureRecognizer Handles-(void) handleTap:(UITapGestureRecognizer *)recognizer{    NSLog(@"---单击手势-------");}

 

UIView单击手势的添加