Xcode / iOS:如何在向下滚动时隐藏Navigation- AND ToolBar? [英] Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?

查看:102
本文介绍了Xcode / iOS:如何在向下滚动时隐藏Navigation- AND ToolBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的iPhone上向下滚动两个栏。当我向上滚动时,它们应该再次出现..我该如何处理?

I would like to hide both bars on scroll down on my iPhone. When I scroll up, they should appear again.. How can I handle this?

推荐答案

接受的答案对我不起作用,如 scrollViewWillBeginScroll:不是委托方法。

The accepted answer does not work for me, as scrollViewWillBeginScroll: is not a delegate method.

相反,我

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldHide" object:self];

}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView 
                 willDecelerate:(BOOL)decelerate
{
    if(!decelerate)
        [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide" 
                                                            object:self];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide"
                                                        object:self];
}

app对象中的任何地方都可以收听此通知,例如

Anywhere in the app objects can listen for this notification,like

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldHide" 
                                                      object:nil
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
        //hide tab bar with animation;
    }];
    [[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldUnhide" 
                                                      object:nil
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
        //Unhide tab bar with animation;
    }];
}

此代码将隐藏任何滚动条。如果你想只关闭,那么在接受的答案中应该有相同的 locationOffset 技巧。

This code will hide the bars for any scroll. if you want to have only on down, the same locationOffset trick as in the accepted answer should work.

这篇关于Xcode / iOS:如何在向下滚动时隐藏Navigation- AND ToolBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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