Click the button to add iOS mobile event

1, the reasons can not be moved when the button clicks than we see in this article are more or less there is such doubt, the reason is very simple, because the button click method and its animation is not at the same level the above structure, because when we move the button, move its layer, which is the top layer of the view click method, we see movement button, the button is actually a layer on the move. The actual frame button or has not moved or has been moved over.

2, about the actual frame button in what I am here to explain to you, this and the button's method of moving a relationship, if the animation methods of UIView, then when the button to move the beginning, click the method has come to end location, you must click on to the final position. CAAnimation method, then click the button to move the process approach has been the initial position. Click method to change the position at the end.

To solve this problem, here is what I find the Internet: Click the Click event but not the button. It is reproduced in part below.

Happy new products to meet new demands and start working full of joy, only to find the results of a study of the afternoon, I want to be too simple, too simple it is to me.

Demand is so similar to the effect of snow, randomly generated number of small snowflakes, each snowflake can then click to the next page.

After receiving the demand for my first idea is to use the button does not realize it, something more than simple, the result after practice to know how ignorant myself, button on the move there is no way that the click event.

Then colleagues are given a solution to get the position clicked through gestures, then traverse the controls on the page, if you click in this range success. With this idea I try to use frame needs to achieve, and then found himself an idiot, all the "snow" in the frame on the page, are the end of the animation of the location, not the real-time position.

But I use gestures, then by position, traverse, this idea should be right, so continue to Baidu, I found a good thing.

- (nullable CALayer *)hitTest:(CGPoint)p;

/* Returns true if the bounds of the layer contains point 'p'. */

Through this you can get if the pages covering this point, so that you can solve my problem, the gesture added to the "snow" of the parent page, then click on the event in the process (of course, using this method would not necessarily use button )

This will solve the problem, of course, other methods should also welcome supplement.

NOTE: If you are unable to click on the view, of course, this method is useful, but if you want to click on a button that, which would have been a click event, then you need to click on the button above to close the event, or will overwrite tap gesture click event, button click event you can not click. Namely: button.userInteractionEnabled = NO; essential, otherwise click on the button there will be some problems

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    view.userInteractionEnabled = YES;
    [UIView addGestureRecognizer:tap];
//记得给你的button添加tag值,要不不容易区分不同button的响应
-(void)tapClick:(UITapGestureRecognizer *)tap
{
    CGPoint clickPoint =  [tap locationInView:self];

    for (UIButton * button in [self subviews])
    {
        if (CGRectContainsPoint(button.layer.presentationLayer.frame, clickPoint))
        {

            // This button was hit whilst moving - do something with it here

            break;
        }
    }
}

In fact CGRectContainsPoint relatively easier to understand some of it, is imageView the frame contains clickPoint, then perform the following steps.

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

Published 83 original articles · won praise 12 · views 180 000 +

Guess you like

Origin blog.csdn.net/shengdaVolleyball/article/details/61192293