第三十九篇、NavBar動態隱藏、設置透明、毛玻璃效果


1.動態隱藏

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    //  1.tableView
    [self.view addSubview:self.tableView];
}

#pragma mark - 滑動隱藏導航欄
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y + _tableView.contentInset.top;//注意
    CGFloat panTranslationY = [scrollView.panGestureRecognizer translationInView:self.tableView].y;
    
    if (offsetY > 64) {
        if (panTranslationY > 0) { //下滑趨勢,顯示
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        }
        else {  //上滑趨勢,隱藏
            [self.navigationController setNavigationBarHidden:YES animated:YES];
        }
    }
    else {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    
//    NSLog(@"%lf %lf", [scrollView.panGestureRecognizer translationInView:self.tableView].y, offsetY);
}

 

2.設置透明

[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:_alphaMemory];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM