UITableView:向上滑动缩小标签栏和导航栏 [英] UITableView: Shrink Tab Bar and Navigation Bar on Swipe up

查看:445
本文介绍了UITableView:向上滑动缩小标签栏和导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景

我有一个应用程序,它使用标签栏控制器(屏幕底部)和导航控制器(顶部的屏幕)UI设计。在一个视图控制器上,我有一个UITableView,其内容是用户将向上滑动以滚动表格以查看内容。

I have an app that uses a Tab Bar Controller (bottom of the screen) with a Navigation Controller (top of the screen) UI design. On one view controller I have a UITableView with content that the user will "Swipe Up" for to scroll through the table to view the content.

需要

与Yahoo!非常相似和Instagram应用程序,我希望能够让顶部导航栏和底部选项卡栏缩小并消失,当它感觉到用户正在桌面视图上向上滑动时。当然,当用户再次滑动时,我希望它们都重新出现。

Much like the Yahoo! and Instagram app, I'd like to be able to have the top Nav Bar and the bottom Tab Bar "shrink" and "disappear" when it senses the user is swiping up on the tableView. And of course, when the user swipes down again, I'd like them both to reappear.

问题

有谁知道怎么做?

推荐答案

隐藏 UITabbar UITabbarController 其中包含 UINavigationController 与堆栈中的 UITableViewController 应使用 hidesBarsOnSwipe 属性并为添加自定义选择器barHideOnSwipeGestureRecognizer

To hide UITabbar of UITabbarController which contains UINavigationController with UITableViewController in stack one should use hidesBarsOnSwipe property and add custom selector for barHideOnSwipeGestureRecognizer:

@implementation SomeTableViewController

- (void)willMoveToParentViewController:(UIViewController *)parent
{
    if (parent) {
        self.navigationController.hidesBarsOnSwipe = YES;
        [self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)];
    }
    else {
        self.navigationController.hidesBarsOnSwipe = NO;
        [self.navigationController.barHideOnSwipeGestureRecognizer removeTarget:self action:@selector(swipe:)];
    }
}

- (void)swipe:(UIPanGestureRecognizer *)recognizer
{
    UINavigationBar *bar = self.navigationController.navigationBar;

    BOOL isHidden = (bar.frame.origin.y < 0);

    [self.tabBarController.tabBar setHidden:isHidden];

    [[UIApplication sharedApplication] setStatusBarHidden:isHidden withAnimation:UIStatusBarAnimationSlide];
}

这样可以隐藏tabbar和statusBar。还可以添加一些动画效果来隐藏/显示这些条形。

In this way one can hide both tabbar and statusBar. Also one can add some animation effects for hiding/revealing these bars.

self 已被解除分配。否则,下次使用 barHideOnSwipeGestureRecognizer 时,您将获得 self.navigationController 的保证。

It is very important to remove selector before self has been deallocated. Otherwise, you will get guaranteed crash on the next use of barHideOnSwipeGestureRecognizer with self.navigationController.

注意这种方法仅适用于iOS8 +。

Note this approach is admissible only for iOS8+.

这篇关于UITableView:向上滑动缩小标签栏和导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆