Showing UI Element with Animation on iPhone

2019-09-20 01:00发布

问题:

Is there a way to do the following without an instant hide/unhide? Or do I have to make everything a separate view or something complicated? A simple fade in fade out like the modal transition style is all I'm looking for.

-(IBAction)someMethod
{
    UIButton.hidden = NO;
    tableView.hidden = NO;
}

-(void)viewDidLoad
{
    UIbutton.hidden = YES;
    tableView.hidden = YES;
}

回答1:

You could animate the alpha value:

[UIView animateWithDuration:0.5f animations:^{
    button.alpha = 0.0f;
    tableView.alpha = 0.0f;
}];

and it's counterpart

[UIView animateWithDuration:0.5f animations:^{
    button.alpha = 1.0f;
    tableView.alpha = 1.0f;
}];


回答2:

   [UIView animateWithDuration:2.0f
                     animations:^ {
UIButton.alpha = 1;
 UIButton.hidden = NO;
tableView.alpha = 1
    tableView.hidden = NO;
                     }];

Do the opposite for hide and change the duration to your need.