簡體   English   中英

使用UITabBar的hidesBarsOnSwipe

[英]hidesBarsOnSwipe with UITabBar

我最近切換到在我的應用程序中使用UITabBarController ,並沒有發現我無法使hidesBarsOnSwipe能夠使我很開心。 我曾經簡單地說過(在視圖控制器中) hidesBarsOnSwipe = true ,但是現在不起作用了。 如果有人可以幫助我完成這項工作,那就太好了。

謝謝!

您可以將操作添加到hideOnSwipe中,如下所示

[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipeGesture:)];

在swipeGesture方法中添加所需的代碼。 隱藏/取消隱藏標簽欄。

我解決了這個問題。 我已經將UITabBarController嵌入到UINavigationController ,並將其作為窗口的根視圖控制器。 當我將根目錄設置為標簽欄控制器后,它就像一個魅力一樣工作。

謝謝!

在迅速

  self.navigationController?.barHideOnSwipeGestureRecognizer.addTarget(self, action: "swipeGestuere")  

聲明一個隱藏的變量,這有助於使標簽欄返回

 func swipeGestuere() {
    if (hidden == true){         
    self.bottomTabBar.isHidden = true
        hidden = false
    }
    else{
        self.bottomTabBar.isHidden = false
        hidden = true
    }

}                             

我通過調整 UITabBarController大小剛好足以使選項卡欄脫離屏幕來解決此問題:

- (void)setTabBarHidden:(BOOL)hidden
{
    CGRect frame = self.originalViewFrame;
    if (hidden)
    {
        frame.size.height += self.tabBar.size.height;
    }
    self.view.frame = frame;
}

然后,您可以將KVO添加到滾動視圖中:

[scrollView addObserver:self
             forKeyPath:@"contentOffset"
                options:NSKeyValueObservingOptionOld
                context:nil];

並在滾動條上隱藏/顯示標簽欄:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    CGPoint oldOffset = [(NSValue *)change[NSKeyValueChangeOldKey] CGPointValue];

    if (!_hidesBarsOnScroll || _scrollView.contentOffset.y == oldOffset.y)
        return;

    // Show on scroll up
    if (_barsHidden &&
        scrollView.contentOffset.y < oldOffset.y &&
        scrollView.contentOffset.y + scrollView.bounds.size.height < scrollView.contentSize.height) // Skip on bottom
    {
        [self.navigationController setNavigationBarHidden:NO
                                                 animated:YES]; // Also navigation bar!
        [self.tabBarController setTabBarHidden:NO
                                      animated:YES];
        _barsHidden = NO;
    }

    // Hide on scroll down
    if (!_barsHidden &&
        scrollView.contentOffset.y > 0 && // Skip on top
        scrollView.contentOffset.y > oldOffset.y)
    {
        [self.navigationController setNavigationBarHidden:YES
                                                 animated:YES];
        [self.tabBarController setTabBarHidden:YES
                                      animated:YES];
        _barsHidden = YES;
    }
}

您可以在這里查看此實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM