UIButton not responding after animation

后端 未结 3 1639
萌比男神i
萌比男神i 2021-01-13 11:14

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

相关标签:
3条回答
  • 2021-01-13 11:36

    I downloaded your project and it seems the translation you're making for self.view. So the actionHiddenButton is not in the frame.Its better to have the controls you want to animate in the separate view.
    If you want to see the problem, after your view get transformed set clipsToBounds to YES. Like

        self.view.transform = translation;
        self.view.clipsToBounds = YES;
    
    0 讨论(0)
  • 2021-01-13 11:41

    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?

    0 讨论(0)
  • 2021-01-13 11:41

    Yipeee!!! Below is how I did.

    .h

    Added new variable.

    @property (retain, nonatomic) NSString *hideStatus;
    

    .m

    -(void) viewDidAppear:(BOOL)animated {
        NSLog(@"viewDidAppear");
        CGAffineTransform translation = CGAffineTransformIdentity;
        translation = CGAffineTransformMakeTranslation(0, -100);
        self.view.transform = translation;
        self.view.clipsToBounds = YES;
        [UIView commitAnimations];
        self.view.frame = CGRectMake(0,-80,320,560);
        hideStatus = @"hidden";
    }
    
    - (IBAction)showHiddenButton:(id)sender {
        NSLog(@"hideStatus===%@", hideStatus);
        CGAffineTransform translation = CGAffineTransformIdentity;
        if ([hideStatus isEqualToString:@"hidden"]) {
            translation = CGAffineTransformMakeTranslation(0, 0);
            hideStatus = @"shown";
        } else {
            translation = CGAffineTransformMakeTranslation(0, -100);
            hideStatus = @"hidden";
        }
    
        [UIView beginAnimations:nil context:nil];
        self.view.transform = translation;
        self.view.clipsToBounds = YES;
        [UIView commitAnimations];
    }
    

    Attached is the sample project. You can download from here.

    0 讨论(0)
提交回复
热议问题