Xcode button when navigating with UIViewAnimation

I can’t do a button action when the button is moving. Can someone help me how to hide the moving button when I click on it? It does not respond when I press the button. here is the code:

-(void)createTurtle
{

    NSUInteger r = arc4random_uniform(284) + 1;

    NSUInteger randomTitle = arc4random_uniform(1000000) + 1;

    turtle = [[UIButton alloc] init];
    turtle.frame = CGRectMake(r, 0, 36, 47);
    [turtle setImage:[UIImage imageNamed:@"turtle.png"] forState:UIControlStateNormal];
    [turtle addTarget:self action:@selector(turtleTouched:) forControlEvents:UIControlEventTouchDown];
    [turtle setTitle:[NSString stringWithFormat:@"%lu", (unsigned long)randomTitle] forState:UIControlStateNormal];
    [turtle setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view bringSubviewToFront:turtle];
    [self.view addSubview:turtle];



    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:16];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    turtle.frame = CGRectMake(turtle.frame.origin.x, self.view.frame.size.height, 36, 47);
    [UIView commitAnimations];


}







    - (void) turtleTouched: (id) sender
{
    UIButton *button = sender; // Typecast sender
    button.hidden = YES;
}
+3
source share
2 answers

your method will not work even if you click on it. but he is will fire when you click in its final frameduring the animation.

Suppose your button has a built-in frame (0,0,100,100),
now you move it to the frame (200,200,100,100).

while moving, if you click in the area (200,200,100,100)-final frame, you will receive events. but in areas middle of pathsuch as (50,50,100,100), you will not receive events.

, , , .

, touchesBegan viewController , transitional frame.

transitionFrame = [button.layer.presentationLayer frame];

.

:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    CGPoint p =[((UITouch *)[touches anyObject]) locationInView:self.view];
    CGRect r= [turtle.layer.presentationLayer frame];
    BOOL contains= CGRectContainsPoint(r, p);
    if(contains)
        turtle.hidden=YES;

}
+1

:

- (void) turtleTouched: (id) sender 
{
  UIButton *button = sender; // Typecast sender
  button.hidden = YES;
}

, :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       buttonNamr.hidden =YES;
}
+1

All Articles