iOS tableView滑動隱藏/顯示tabbar

在需要滑動隱藏/顯示的頁面中:

@property(nonatomic,assign)CGFloat historyY;

#pragma mark Delegate

//設(shè)置滑動的判定范圍
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    if (historyY+20<targetContentOffset->y)
    {
        [self setTabBarHidden:YES];
    }
    else if(historyY-20>targetContentOffset->y)
    {
        
        [self setTabBarHidden:NO];
    }
    historyY=targetContentOffset->y;
}
//隱藏顯示tabbar
- (void)setTabBarHidden:(BOOL)hidden
{
    UIView *tab = self.tabBarController.view;
    CGRect  tabRect=self.tabBarController.tabBar.frame;
    if ([tab.subviews count] < 2) {
        return;
    }
    
    UIView *view;
    if ([[tab.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
        view = [tab.subviews objectAtIndex:1];
    } else {
        view = [tab.subviews objectAtIndex:0];
    }
    
    if (hidden) {
        view.frame = tab.bounds;
        tabRect.origin.y=[[UIScreen mainScreen]bounds].size.height+self.tabBarController.tabBar.frame.size.height;
    } else {
        view.frame = CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y, tab.bounds.size.width, tab.bounds.size.height);
        tabRect.origin.y=[[UIScreen mainScreen] bounds].size.height-self.tabBarController.tabBar.frame.size.height;
    }
    
    [UIView animateWithDuration:0.5f animations:^{
        self.tabBarController.tabBar.frame=tabRect;
    }completion:^(BOOL finished) {
        
    }];
    
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,917評論 25 709
  • 之前在做直播的時候,參照了映客App,發(fā)現(xiàn)其首頁的效果還挺不錯,在網(wǎng)上找了一下相關(guān)仿映客App代碼和博客,大部分都...
    HK_Hank閱讀 9,433評論 17 114
  • 暗戀是一朵食人花 明艷,要人命 跟所有女孩一樣,我無可救藥的喜歡上了一個人,而且,他是我初一的同學(xué),陪伴走過了初中...
    三毛的撒哈拉閱讀 271評論 0 0
  • 兩只蝸牛 我是一只蝸牛 你是一只蝸牛 我們慢慢地慢慢地走著 我們慢慢地慢慢地接近了 放佛過了一個世紀那么長 我們終...
    意大利空姐亞亞閱讀 1,280評論 0 2
  • 人的一生中都有最難忘的事,我最難忘的有很多,但有一件事令我終身難忘,也時時出現(xiàn)在我的腦海里! 那一天,天氣很明媚,...
    曾嘉文閱讀 416評論 0 2

友情鏈接更多精彩內(nèi)容