顺利隐藏导航栏

Posted

技术标签:

【中文标题】顺利隐藏导航栏【英文标题】:smoothly Hidden navigation bar 【发布时间】:2014-07-12 06:26:02 【问题描述】:

如何在不调整视图框架(或 tableView)的情况下做到这一点? 我使用此代码并调整了视图大小,然后向下/向上滚动 我使用代码,而不是故事板

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
 
if ([gestureRecognizer class] == [UIPanGestureRecognizer class])

    UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer;
    CGPoint distance = [panGestureRec translationInView:self.tableView];

    if (distance.y > 0 || distance.y < 0)
    
        if (distance.y > 0) // down
        
            //NSLog(@"user swiped down");
            [self.navigationController setNavigationBarHidden:YES animated:YES];

         else if (distance.y < 0) //up
        
            //NSLog(@"user swiped up");
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        

        return NO;
     else 
        return YES;
    

return YES;

【问题讨论】:

【参考方案1】:

试试这个代码。这将提供流畅的动画(使用 UIView 动画属性)

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
 
if ([gestureRecognizer class] == [UIPanGestureRecognizer class])


    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];

    UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer;
    CGPoint distance = [panGestureRec translationInView:self.tableView];

    if (distance.y > 0 || distance.y < 0)
    
        if (distance.y > 0) // down
        
            //NSLog(@"user swiped down");
            [self.navigationController setNavigationBarHidden:YES animated:YES];

         else if (distance.y < 0) //up
        
            //NSLog(@"user swiped up");
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        

        return NO;
     else 
        return YES;
    

   [UIView commitAnimations];

return YES;

【讨论】:

将 UIView 动画代码放入 if 条件中(if (distance.y > 0 || distance.y

以上是关于顺利隐藏导航栏的主要内容,如果未能解决你的问题,请参考以下文章

Electron菜单栏&导航栏隐藏

Android 显示、隐藏状态栏和导航栏

Android导航栏隐藏与浮现(二)

android关掉导航栏后怎么

导航栏状态,显示和隐藏底部导航栏

vue中导航栏的显示和隐藏