setNavigationBarHidden with animation not working

2019-08-03 15:54发布

问题:

I use the following code in my app when user click on a button :

[self.navigationController setNavigationBarHidden:NO animated:YES];

The appearance animates normally on iPhone but not on iPad. Do you know why ?

回答1:

The best solution here may be to put self.navigationBar.hidden = NO; in the -viewWillAppear: method of the UIViewController where you dont wish to have the bar perpetually hidden.

EDIT:

i found this, may help you;

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
    CGRect rect = self.navigationController.navigationBar.frame;
    rect.origin.y = rect.origin.y < 0 ?
        rect.origin.y + rect.size.height
    :   rect.origin.y - rect.size.height;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.2];
    self.navigationController.navigationBar.frame = rect;
    [UIView commitAnimations];
}
else 
{
    [self.navigationController setNavigationBarHidden:shouldHide animated:YES];
}


回答2:

Are you sure you're invoking this in the context of the Main Thread ?



回答3:

Do check the other code you have written along with the properties of your view. I use this fragment in my universal apps and it works fine on both the iPhone and iPad. So looks like some other setting (probably autosizing properties??) of your views are causing this.



回答4:

This code is working fine for me. I try with navigation templete for iphone and then that project upgrade for the ipad for two specific device. and run in ipad. Then navigation bar is hide/show with same animation like iphone app does.

try this. May you get more idea.

Thanks,

MinuMaster