iOS 个人页面展示(导航条操作)

2016-11-30  本文已影响0人  azhang_coder

1.搭建基本界面

2.在AZViewController中进行界面操作

// 设置tableView的代理和数据源
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    // 设置tableView的位置
    self.tableView.contentInset=UIEdgeInsetsMake(244, 0, 0, 0);
    self.automaticallyAdjustsScrollViewInsets=NO;
    // 注册tableViewCell的引用标识
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
    // 设置导航栏样式
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
    // 设置导航栏的标题
    UILabel *title=[[UILabel alloc]init];
    title.text=@"个人详情页";
    [title sizeToFit];
    title.textColor=[UIColor colorWithWhite:0 alpha:0];
    
    self.navigationItem.titleView=title;

3.页面效果实现

#pragma mark - UIScrollView的代理方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // y轴位移
    CGFloat offset=scrollView.contentOffset.y-(oriOfftY);
    // 图片底部距离上方高度
    CGFloat h=oriHeight-offset;
    // 滚动到导航栏位置停止滚动
    self.bgImageHeight.constant=h<64?64:h;
    // 根据位移量设置透明度
    CGFloat alpha=offset*1/136.0;
    if (alpha>=1) {
        alpha=0.99;
    }
    // 设置导航栏标题的透明度,设置导航栏标题的alpha无法直接修改,可以通过修改label的文字颜色的方式来修改
    UILabel *titleL=(UILabel *)self.navigationItem.titleView;
    titleL.textColor=[UIColor colorWithWhite:0 alpha:alpha];
    self.navigationItem.titleView=titleL;
   
    // 设置导航条的透明,同样无法直接修改alpha,通过设置背景图片的alpha值来修改导航栏的透明度
    UIImage *alphaColor=[UIImage imageWithColor:[UIColor colorWithWhite:1 alpha:alpha]];
    [self.navigationController.navigationBar setBackgroundImage:alphaColor forBarMetrics:UIBarMetricsDefault];
    
}
上一篇下一篇

猜你喜欢

热点阅读