在iPhone上像Instagram或Facebook一样隐藏导航栏?

4

我有一个应用程序,希望在UITableView向上滚动时隐藏导航栏。我是这样做的:

- (void)scrollViewDidScroll:(UIScrollView *)sender {

    //Initializing the views and the new frame sizes.
    UINavigationBar *navbar = self.navigationController.navigationBar;
    UIView *tableView = self.view;

    CGRect navBarFrame = self.navigationController.navigationBar.frame;
    CGRect tableFrame = self.view.frame;

    //changing the origin.y based on the current scroll view.
    //Adding +20 for the Status Bar since the offset is tied into that.
    navBarFrame.origin.y = MIN(0, (sender.contentOffset.y * -1)) +20;
    navbar.frame = navBarFrame;

    tableFrame.origin.y = MIN(0,MAX(-44,(sender.contentOffset.y * -1)));
    tableView.frame = tableFrame;    
}

但问题是在iOS 7中,它会完全向上移动。我需要它停在状态栏下面,并显示状态栏。


2
请查看此库 https://github.com/andreamazz/AMScrollingNavbar - The dude
1
你尝试过这些解决方案吗?https://dev59.com/QWIj5IYBdhLWcg3w24kF - David Omid
我尝试了所有的方法,在第一种方法中,当滚动开始时,内容偏移量会改变,而不是回到0。 - hacker
@Thedude提到的项目非常易于使用。但是当导航栏重新出现时,表格视图和导航栏之间会添加一个间隙。我该如何防止/删除该间隙? - Katedral Pillon
你是否在viewDidAppear方法中尝试过self.navigationController.hidesBarsOnSwipe = YES; - Husein Behboudi Rad
显示剩余2条评论
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接