IOS responds to button click events on UIView with UITapGestureRecognizer added

Source: Internet
Author: User

SOURCE http://blog.sina.com.cn/s/blog_59fb90df0101apn4.html, click here to view the original

as figure, the following is nested inside the cell , to tableview added a click event, jump to the View details interface, now I need to click the more buttons below, jump to see more friends interface, and click on the white space in the red circle does not respond , that is, do not jump to the view details screen.

Because it is in a cell , so I used a uiview to put up the hot friends, add uitapgesturerecognizer, and then do not operate in the method, The realization of the above click on the red circle of the white space will not jump to the viewing interface, equivalent to the UITapGestureRecognizer event covering the TableView Click event, but, when I am full of expectations of the run, yes, Click on the blank will not jump, but when I click More,UIButton Click event does not respond, after a round of Baidu search, in a blog to find a solution, blog address on the above, interested friends can see, blog summary:

After adding UITapGestureRecognizer to the view, all touch events on this view are absorbed by the UITapGestureRecognizer, so to solve this bug, To add some event filtering to this gesture agent, do not intercept the button event . The code is as follows :

UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (CILCK)]; Tapgesture.delegate = self; [Friendview addgesturerecognizer:tapgesture]; #pragma mark uigesturerecognizerdelegate-(BOOL) Gesturerecognizer: ( Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch{        if ([Touch.view isKindOfClass:[ UIButton class]) {        //Leave button clicked to intercept        return NO;    else{        return YES;    }    }
ThanksThe original author's share, with the above code to successfully achieve the effect I want,button event also successfully responded.

This is recorded for later inspection.

IOS responds to button click events on UIView with UITapGestureRecognizer added

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.