美文网首页
iOS日常基础记录8

iOS日常基础记录8

作者: 恋空K | 来源:发表于2022-10-26 15:40 被阅读0次

设置了这个contentInset就会变成(0,0,0,0)

如果用的是代码中的模式,整个导航条就会变得透明。生成的图片是半透明的




scrollView向下滚动偏移量y是负的
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    //偏移量
    CGFloat offset = scrollView.contentOffset.y - oriOffsetY;
    NSLog(@" offset = %f",offset);
    
    //原始的高度-偏移量
    CGFloat h = oriH - offset;
    if (h <= 64) {
        h = 64;
    }
    //更新高度
    self.heightConstr.constant = h;
    
    //动态求出alpha
    //求变化的值.
    //最大值的方法
    //1.最大值为多少 (最大为1)
    //2.什么情况下最大. (当offset 等于 136.0 最大)
    //  当offset 等于 136.0的时候 alpha = 1
    //  当变化的值 等于 固定值 的时候 为最大
    CGFloat alpha = offset * 1 / 136.0;
    
    if (alpha >= 1) {
        alpha = 0.99;
    }
    //根据一个颜色,生成一张图片
    UIColor *color = [UIColor colorWithWhite:1.0 alpha:alpha];
    UIImage *image = [UIImage imageWithColor:color];
    
    //设置背景图片
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
    //设置头部标题的透明度
    //self.titleV.textColor = [UIColor colorWithWhite:0 alpha:alpha];
    
    UILabel *titleV = (UILabel *)self.navigationItem.titleView;
    titleV.textColor = [UIColor colorWithWhite:0 alpha:alpha];
}
    UILabel *titleV = [[UILabel alloc] init];
    titleV.text = @"个人详情页";
    [titleV sizeToFit];
    titleV.textColor = [UIColor colorWithWhite:0 alpha:0];
    
    self.navigationItem.titleView = titleV;

uitabbar的高度是49,导航条的高度是44,y值是20

上面代码对应下图

上面代码对应下图
默认显示的是第一个添加的控制器的view

切换tabbar的时候,先移除原先的view,在把新的view添加上去显示





网友评论

      本文标题:iOS日常基础记录8

      本文链接:https://www.haomeiwen.com/subject/tflnzrtx.html