IOS adds click events for UIView (UIButton) in the move

Source: Internet
Author: User

Happy to meet the new product demand, full of joy to start work, the results of a study of the afternoon only to find that it is too simple for me to think, I am too naïve.

The demand is such a snow-like effect that randomly produces some small snowflakes, and then each snowflake can be clicked on to the next page.

After receiving the demand, my first idea is to use the button to achieve a short time, more simple things, the results of practice will know how ignorant of their own, in the mobile button at all there is no way to receive click events.

The colleague then gives a solution to get the click position through the gesture and then traverse the controls on the page if the click succeeds within that range. Through this idea I tried to use frame to achieve the requirements, and then found that I am an idiot, the page all the "snowflake" frame, is the end of the animation position, not real-time location.

But I feel the gesture, and then through the position, traverse, this idea should be right, so continue to Baidu, found a good thing

-(Calayer *) HitTest: (Cgpoint) p;

Through this can get this page to cover this point, so that you can solve my problem, the gesture is added to the "snowflake" on the parent page, and then click on the event to deal with (of course, there is no need to use this method must be a button)

-(void) Tapclick: (UITapGestureRecognizer *) tap{       cgpoint clickpoint =  [tap locationinview:self];        For (Uiimageview *imageview in [self subviews])        {            if ([ImageView.layer.presentationLayer hittest:clickpoint])            {                //This button is hit whilst moving-do something with it here break                               ;        }    }}

This will solve the problem, of course, there should be other methods, welcome to add.

A link to help me with my problem-solving information

http://www.999dh.net/home.php?mod=space&uid=1&do=blog&id=410

Http://stackoverflow.com/questions/8346100/uibutton-cant-be-touched-while-animated-with-uiview-animatewithduration

IOS adds click events for UIView (UIButton) in the move

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.