//原理:
//1.设置导航栏透明色
关键代码是:self.navigationController.navigationBar.translucent = YES;
//2.向导行栏navigationBar中底层添加一个view用他的颜色变化控制导航栏的变化(注意大小要算上状态栏20个高度)
关键代码:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
//统一导航样式
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//去掉透明后导航栏下边的黑边
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
//关键代码控制导航栏颜色
self.naviNew = [[UIView alloc]initWithFrame:CGRectMake(0, -20, self.navigationController.navigationBar.bounds.size.width,self.navigationController.navigationBar.bounds.size.height+20)];
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:0];
[self.navigationController.navigationBar insertSubview:self.naviNew atIndex:0];
}
//3.在scrollView代理方法里面写逻辑
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint point = scrollView.contentOffset;
if (point.y < 0) {
//不能向上拉的逻辑
self.myTableView.contentOffset = CGPointMake(0.0, 0.0);
self.myTableView.userInteractionEnabled = YES;
}
NSLog(@"point %@",NSStringFromCGPoint(point));
//变色的逻辑
if (point.y>=136&&point.y<=200) {
CGFloat ap = (point.y-136)/64;
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:ap];
}else if (point.y>200){
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:1];
}else{
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:0];
}
}
#import "MineMainViewController.h"
#import "ConstantHeader.h"
#import <Masonry/Masonry.h>
#import "MineTableViewCell.h"
//我的笔记
#import "MineNotesViewController.h"
#import "MineNotesChooseViewController.h"
#import "DynamicHttpTool.h"
#import "MBProgressHUD+QSJ.h"
#import "AlertUtil.h"
#import "MJRefresh.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "GetUserSelfInfoDTO.h"
#import "GetUserSelfInfoDetailDTO.h"
@interface MineMainViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView *myTableView;
@property(nonatomic,strong) NSMutableArray<NSString *> *dataArr;
@property(nonatomic,strong) UIButton *guanZhuBtn;
@property(nonatomic,strong) UIButton *fenSiBtn;
@property(nonatomic,strong) UILabel *beiZhanLabel;
@property(nonatomic,strong) UILabel *beiShouCangLabel;
@property(nonatomic,strong) UIView *naviNew;
@end
@implementation MineMainViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = YES;
self.myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
[self.view addSubview:self.myTableView];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.myTableView.estimatedRowHeight = 40;
self.myTableView.rowHeight = UITableViewAutomaticDimension;
self.myTableView.backgroundColor = NORMAL_BKG_GREY;
[self.myTableView registerClass:[MineTableViewCell class] forCellReuseIdentifier:@"MineTableViewCell"];
self.myTableView.userInteractionEnabled = YES;
self.myTableView.showsVerticalScrollIndicator = NO;
self.myTableView.showsHorizontalScrollIndicator = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.view);
make.size.mas_equalTo(self.view);
}];
#pragma mark---请求个人信息---
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[DynamicHttpTool getUserSelfInfoSuccess:^(GetUserSelfInfoDTO *result) {
[hud hide:YES];
//huo取个人信息
GetUserSelfInfoDetailDTO *model = result.userSelfInfo;
//设置headerview
UIView *headerView = [[UIView alloc]init];
self.myTableView.tableHeaderView = headerView;
headerView.backgroundColor = [UIColor whiteColor];
[headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(200+43+TEXT_LINE_DISTANCE);
}];
UIView *shangHeaderView = [[UIView alloc]init];
[headerView addSubview:shangHeaderView];
shangHeaderView.backgroundColor = PINK_DARK_COLOR;
[shangHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(headerView.mas_top);
make.left.mas_equalTo(headerView.mas_left);
make.width.mas_equalTo(headerView.mas_width);
make.height.mas_equalTo(200);
}];
//头像
UIImageView *headImgv = [[UIImageView alloc]init];
[shangHeaderView addSubview:headImgv];
headImgv.layer.cornerRadius = 85/2;
headImgv.layer.masksToBounds = YES;
headImgv.backgroundColor = [UIColor whiteColor];
[headImgv sd_setImageWithURL:[NSURL URLWithString:model.userPhotoUrl] placeholderImage:[UIImage imageNamed:@"chatListCellHead"]];
[headImgv mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(shangHeaderView.mas_centerX);
make.top.mas_equalTo(shangHeaderView.mas_top).mas_offset(35);
make.size.mas_equalTo(CGSizeMake(85, 85));
}];
//名字
UILabel *nameLabel = [[UILabel alloc]init];
[shangHeaderView addSubview:nameLabel];
nameLabel.font = NORMAL_SECOND_FONT;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.text = model.nickName;
nameLabel.textAlignment = NSTextAlignmentCenter;
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(headImgv.mas_bottom).mas_offset(TEXT_EDGE_DISTANCE);
make.centerX.mas_equalTo(headImgv.mas_centerX);
make.left.mas_equalTo(TEXT_EDGE_DISTANCE);
make.width.mas_greaterThanOrEqualTo(5);
make.height.mas_lessThanOrEqualTo(35);
}];
//地址
UILabel *addressL = [[UILabel alloc]init];
[shangHeaderView addSubview:addressL];
addressL.font = LITTLE_FONT;
addressL.textColor = [UIColor whiteColor];
addressL.text = model.distName;
[addressL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(nameLabel.mas_bottom).mas_offset(TEXT_LINE_DISTANCE);
make.centerX.mas_equalTo(headImgv.mas_centerX).mas_offset(15);
make.left.mas_greaterThanOrEqualTo(TEXT_LINE_DISTANCE+15);
make.width.mas_greaterThanOrEqualTo(5);
}];
//图标
UIImageView *addressIcon = [[UIImageView alloc]init];
[shangHeaderView addSubview:addressIcon];
addressIcon.image = [UIImage imageNamed:@"temp_address"];
[addressIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(addressL.mas_centerY);
make.right.mas_equalTo(addressL.mas_left).mas_offset(-5);
make.size.mas_equalTo(CGSizeMake(15, 15));
}];
[shangHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(200);
}];
//下面工具栏
//关注
self.guanZhuBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[headerView addSubview:self.guanZhuBtn];
self.guanZhuBtn.titleLabel.font = LITTLE_SECOND_FONT;
self.guanZhuBtn.backgroundColor = [UIColor whiteColor];
[self.guanZhuBtn setTintColor:TEXT_DARK_BLACK];
[self.guanZhuBtn setTitle:@"关注(5)" forState:UIControlStateNormal];
[self.guanZhuBtn setTitle:[NSString stringWithFormat:@"关注(%@)",model.followCnt] forState:UIControlStateNormal];
[self.guanZhuBtn addTarget:self action:@selector(clickedGuanZhuBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.guanZhuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangHeaderView.mas_bottom);
make.left.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH/4-3);
make.height.mas_equalTo(43);
}];
//线
UIView *lineOne = [[UIView alloc]init];
[headerView addSubview:lineOne];
lineOne.backgroundColor = TEXT_LIGHT_BLACK_GREY;
[lineOne mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.guanZhuBtn.mas_centerY);
make.left.mas_equalTo(self.guanZhuBtn.mas_right);
make.width.mas_equalTo(1);
make.height.mas_equalTo(self.guanZhuBtn.mas_height).mas_offset(-10);
}];
//粉丝
self.fenSiBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[headerView addSubview:self.fenSiBtn];
self.fenSiBtn.titleLabel.font = LITTLE_SECOND_FONT;
self.fenSiBtn.backgroundColor = [UIColor whiteColor];
[self.fenSiBtn setTintColor:TEXT_DARK_BLACK];
[self.fenSiBtn setTitle:@"粉丝(5)" forState:UIControlStateNormal];
[self.fenSiBtn setTitle:[NSString stringWithFormat:@"粉丝(%@)",model.fansCnt] forState:UIControlStateNormal];
[self.fenSiBtn addTarget:self action:@selector(clickedFenSiBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.fenSiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangHeaderView.mas_bottom);
make.left.mas_equalTo(lineOne.mas_right);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH/4-3);
make.height.mas_equalTo(43);
}];
//线
UIView *lineTwo = [[UIView alloc]init];
[headerView addSubview:lineTwo];
lineTwo.backgroundColor = TEXT_LIGHT_BLACK_GREY;
[lineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.fenSiBtn.mas_centerY);
make.left.mas_equalTo(self.fenSiBtn.mas_right);
make.width.mas_equalTo(1);
make.height.mas_equalTo(self.fenSiBtn.mas_height).mas_offset(-10);
}];
//被赞
self.beiZhanLabel = [[UILabel alloc]init];
[headerView addSubview:self.beiZhanLabel];
self.beiZhanLabel.font = LITTLE_SECOND_FONT;
self.beiZhanLabel.backgroundColor = [UIColor whiteColor];
self.beiZhanLabel.textColor = TEXT_DARK_BLACK;
self.beiZhanLabel.textAlignment = NSTextAlignmentCenter;
self.beiZhanLabel.text = @"被赞(2)";
self.beiZhanLabel.text = [NSString stringWithFormat:@"被赞(%@)",model.likedCnt];
[self.beiZhanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangHeaderView.mas_bottom);
make.left.mas_equalTo(lineTwo.mas_right);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH/4-3);
make.height.mas_equalTo(43);
}];
//线
UIView *lineThree = [[UIView alloc]init];
[headerView addSubview:lineThree];
lineThree.backgroundColor = TEXT_LIGHT_BLACK_GREY;
[lineThree mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.beiZhanLabel.mas_centerY);
make.left.mas_equalTo(self.beiZhanLabel.mas_right);
make.width.mas_equalTo(1);
make.height.mas_equalTo(self.beiZhanLabel.mas_height).mas_offset(-10);
}];
//被搜藏
self.beiShouCangLabel = [[UILabel alloc]init];
[headerView addSubview:self.beiShouCangLabel];
self.beiShouCangLabel.font = LITTLE_SECOND_FONT;
self.beiShouCangLabel.backgroundColor = [UIColor whiteColor];
self.beiShouCangLabel.textColor = TEXT_DARK_BLACK;
self.beiShouCangLabel.textAlignment = NSTextAlignmentCenter;
self.beiShouCangLabel.text = @"被收藏(8)";
self.beiShouCangLabel.text = [NSString stringWithFormat:@"被收藏(%@)",model.favoritedCnt];
[self.beiShouCangLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangHeaderView.mas_bottom);
make.left.mas_equalTo(lineThree.mas_right);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH/4-3);
make.height.mas_equalTo(43);
}];
UIView *downBKGView = [[UIView alloc]init];
[headerView addSubview:downBKGView];
downBKGView.backgroundColor = NORMAL_BKG_GREY;
[downBKGView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.guanZhuBtn.mas_bottom);
make.left.mas_equalTo(self.guanZhuBtn.mas_left);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(TEXT_LINE_DISTANCE);
}];
[headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(downBKGView.mas_bottom);
}];
//指定tableHeaderView
CGFloat height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect frame = headerView.frame;
frame.size.height = height;
headerView.frame = frame;
self.myTableView.tableFooterView = [[UIView alloc]init];
} failure:^(NSInteger code, NSString *desc) {
[hud showFailure:desc action:nil];
}];
self.dataArr = [@[@"我的厘米",@"收益统计",@"代金券",@"排行榜",@"我的搜藏",@"地址管理",@"客服",@"消息中心",@"我的笔记"] mutableCopy];
//右键
UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
[rightBtn setImage:[UIImage imageNamed:@"temp_chilun"] forState:UIControlStateNormal] ;
[rightBtn addTarget:self action:@selector(rightSettingItemPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
// UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"temp_chilun"]style:UIBarButtonItemStylePlain target:self action:@selector(rightSettingItemPressed:)];
self.navigationItem.rightBarButtonItem = rightButton;
}
//右键
-(void)rightSettingItemPressed:(UIButton *)sender{
NSLog(@"点击了右键");
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
//统一导航样式
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//去掉透明后导航栏下边的黑边
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
self.naviNew = [[UIView alloc]initWithFrame:CGRectMake(0, -20, self.navigationController.navigationBar.bounds.size.width, self.navigationController.navigationBar.bounds.size.height+20)];
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:0];
[self.navigationController.navigationBar insertSubview:self.naviNew atIndex:0];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//统一导航样式
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
[self.naviNew removeFromSuperview];
}
//设置tableview不能下拉
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint point = scrollView.contentOffset;
if (point.y < 0) {
self.myTableView.contentOffset = CGPointMake(0.0, 0.0);
self.myTableView.userInteractionEnabled = YES;
}
NSLog(@"point %@",NSStringFromCGPoint(point));
if (point.y>=136&&point.y<=200) {
CGFloat ap = (point.y-136)/64;
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:ap];
}else if (point.y>200){
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:1];
}else{
self.naviNew.backgroundColor = [UIColor colorWithHexString:@"#ff5179" alpha:0];
}
}
#pragma mark----button----
-(void)clickedGuanZhuBtn:(UIButton *)sender{
NSLog(@"关注跳转");
}
-(void)clickedFenSiBtn:(UIButton *)sender{
NSLog(@"粉丝跳转");
}
#pragma mark -----tableView代理事件-----
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_wodeweili"];
return cell;
}
break;
case 1:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_shouyitongji"];
return cell;
}
break;
case 2:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_daijinquan_icon"];
return cell;
}
break;
case 3:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_paihangbang_icon"];
return cell;
}
break;
case 4:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_wodeshouchang_icon"];
return cell;
}
break;
case 5:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_dizhi_icon"];
return cell;
}
break;
case 6:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_kefu_icon"];
return cell;
}
break;
case 7:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_xiaoxizhongxin_icon"];
return cell;
}
break;
case 8:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_wodebiji_icon"];
return cell;
}
break;
default:
{
MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineTableViewCell" forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.titleTextL.text = self.dataArr[indexPath.row];
cell.titleImgv.image = [UIImage imageNamed:@"mine_wodebiji_icon"];
return cell;
}
break;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.row) {
case 0:
{
}
break;
case 8:
{
MineNotesChooseViewController *vc = [[MineNotesChooseViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.01;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end