setNavigationBarHidden with animation not working

2019-08-03 15:32发布

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 ?

4条回答
The star\"
2楼-- · 2019-08-03 16:07

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];
}
查看更多
forever°为你锁心
3楼-- · 2019-08-03 16:17

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

查看更多
劫难
4楼-- · 2019-08-03 16:21

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.

查看更多
叼着烟拽天下
5楼-- · 2019-08-03 16:31

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

查看更多
登录 后发表回答