Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton not responding after animation

I would prefer first download the project from below link and then continue with question (only 36kb)

Download Link

At start what I have is like below.

enter image description here

When I click My Office button, I am calling action actionSeenButton which will print NSLog(@"actionSeenButton");

- (IBAction)actionSeenButton:(id)sender {
    NSLog(@"actionSeenButton");
}

This works perfect.

When I click, Show hidden button, I am sliding view by 100 and showing the image and buttons that I have at the top, as shown in below image

enter image description here

Code used is

- (IBAction)showHiddenButton:(id)sender {
    CGAffineTransform translation = CGAffineTransformIdentity;
    translation = CGAffineTransformMakeTranslation(0, 100);
    [UIView beginAnimations:nil context:nil];
    self.view.transform = translation;
    [UIView commitAnimations];
}

When I click this button, I am calling action actionHiddenButton which will print NSLog(@"actionHiddenButton");

- (IBAction)actionHiddenButton:(id)sender {
    NSLog(@"actionHiddenButton");
}

BUT the problem is, when I click the new button that I see, action is not getting called.

Any idea why this is happening?


Note

When I move the top hidden button from y=-70 to y=170, action is getting called.

Sample project can be downloaded from here

What I wanted to implement is, showing three buttons (as menu) on the top in one line by moving view down.

like image 310
Fahim Parkar Avatar asked Nov 11 '22 21:11

Fahim Parkar


1 Answers

verify that your button is not behind the frame of another view. even if the button is visable, if there is something covering it up it wont work. i don't have access to xcode at the moment but my guess is your view "stack" is prohibiting you from interacting with the button. a button is esentually a uiview and you can do all the same animations to buttons and labels that you can with views. your best bet is to leave the view in the background alone and just move your buttons. since your "hidden" button isn't part of your main "view" hiarchy thats where your problem is.

upon further investigation, your problem is related to auto-layout and making sure your button object stays in the view hierarchy. if you turn off auto-layout you will see where the problem is. when you animate the main view down the "hidden" button is off of the view and there for inactive. the easiest solution is to just animate the buttons. the next best solution closest to what you have is to add another view onto your "main view" and then put the buttons into that view. also why do you have that background image twice? why not just set the background color of your view to that same yellow?

like image 87
DoS Avatar answered Nov 15 '22 05:11

DoS