Skip to content

Commit

Permalink
增加自定义导航栏变化效果
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunyang committed Jan 19, 2017
1 parent 92199c5 commit 3b40025
Show file tree
Hide file tree
Showing 26 changed files with 492 additions and 1 deletion.
16 changes: 16 additions & 0 deletions MobileProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
342A8FA91D3F1D8B000C7B98 /* UINavigationController+StackManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 342A8F9F1D3F1D8B000C7B98 /* UINavigationController+StackManager.m */; };
342A8FAC1D3F1ED1000C7B98 /* MPQRCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 342A8FAB1D3F1ED1000C7B98 /* MPQRCodeViewController.m */; };
342A8FAD1D3F1ED1000C7B98 /* MPQRCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 342A8FAB1D3F1ED1000C7B98 /* MPQRCodeViewController.m */; };
34300A481E308391000C1FA5 /* MPNavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34300A471E308391000C1FA5 /* MPNavigationViewController.m */; };
34300A491E308391000C1FA5 /* MPNavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34300A471E308391000C1FA5 /* MPNavigationViewController.m */; };
34300A4C1E30840E000C1FA5 /* MPNavView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34300A4B1E30840E000C1FA5 /* MPNavView.m */; };
34300A4D1E30840E000C1FA5 /* MPNavView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34300A4B1E30840E000C1FA5 /* MPNavView.m */; };
34420CB91D0FAC9E007D1AAC /* AdvertiseHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */; };
34420CBA1D0FAC9E007D1AAC /* AdvertiseHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */; };
34420CBD1D0FAD10007D1AAC /* AdvertiseView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CBC1D0FAD10007D1AAC /* AdvertiseView.m */; };
Expand Down Expand Up @@ -1049,6 +1053,10 @@
342A8F9F1D3F1D8B000C7B98 /* UINavigationController+StackManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+StackManager.m"; sourceTree = "<group>"; };
342A8FAA1D3F1ED1000C7B98 /* MPQRCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPQRCodeViewController.h; sourceTree = "<group>"; };
342A8FAB1D3F1ED1000C7B98 /* MPQRCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPQRCodeViewController.m; sourceTree = "<group>"; };
34300A461E308391000C1FA5 /* MPNavigationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNavigationViewController.h; sourceTree = "<group>"; };
34300A471E308391000C1FA5 /* MPNavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNavigationViewController.m; sourceTree = "<group>"; };
34300A4A1E30840E000C1FA5 /* MPNavView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNavView.h; sourceTree = "<group>"; };
34300A4B1E30840E000C1FA5 /* MPNavView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNavView.m; sourceTree = "<group>"; };
34420CB71D0FAC9E007D1AAC /* AdvertiseHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseHelper.h; sourceTree = "<group>"; };
34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvertiseHelper.m; sourceTree = "<group>"; };
34420CBB1D0FAD10007D1AAC /* AdvertiseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3933,6 +3941,8 @@
34FF16A11DD466AD00E84DCC /* MPViewControllerLifeCycle.m */,
340AED331DF45A59007B5CEE /* MPKeyboardViewController.h */,
340AED341DF45A59007B5CEE /* MPKeyboardViewController.m */,
34300A461E308391000C1FA5 /* MPNavigationViewController.h */,
34300A471E308391000C1FA5 /* MPNavigationViewController.m */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -3963,6 +3973,8 @@
34683B121D4EEA0D0041F8A0 /* MPReduceTimeCell.m */,
3461BD0A1DD5C4FE00F8FC14 /* MPMasonryView.h */,
3461BD0B1DD5C4FE00F8FC14 /* MPMasonryView.m */,
34300A4A1E30840E000C1FA5 /* MPNavView.h */,
34300A4B1E30840E000C1FA5 /* MPNavView.m */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -4620,6 +4632,7 @@
3452EB901D1A8DAA0001732E /* AppDelegate.m in Sources */,
34E08B171C3BFB90005C6CA3 /* UIImageView+Reflect.m in Sources */,
340D87A61D3F7079003D9C88 /* MPImageCollectionCell.m in Sources */,
34300A491E308391000C1FA5 /* MPNavigationViewController.m in Sources */,
34E08B181C3BFB90005C6CA3 /* UIView+GestureCallback.m in Sources */,
34E08B191C3BFB90005C6CA3 /* NSURL+Param.m in Sources */,
34683B101D4EE93C0041F8A0 /* MPReduceTimeViewController.m in Sources */,
Expand Down Expand Up @@ -4759,6 +4772,7 @@
34E08B7D1C3BFB90005C6CA3 /* QBAssetsCollectionCheckmarkView.m in Sources */,
34E08B7E1C3BFB90005C6CA3 /* main.m in Sources */,
34E08B7F1C3BFB90005C6CA3 /* MJRefreshAutoStateFooter.m in Sources */,
34300A4D1E30840E000C1FA5 /* MPNavView.m in Sources */,
34E08B811C3BFB90005C6CA3 /* NSObject+MKBlockTimer.m in Sources */,
34E08B821C3BFB90005C6CA3 /* MJRefreshAutoFooter.m in Sources */,
349F81D11D45E571002104E3 /* MPUploadImageItemService.m in Sources */,
Expand Down Expand Up @@ -4945,6 +4959,7 @@
34E893FC1C3B9A03001327C8 /* UINavigationBar+Awesome.m in Sources */,
34E893641C3B9A03001327C8 /* NSManagedObject+Extensions.m in Sources */,
34E8943A1C3B9A03001327C8 /* UIViewController+TopBarMessage.m in Sources */,
34300A481E308391000C1FA5 /* MPNavigationViewController.m in Sources */,
34E893961C3B9A03001327C8 /* NSObject+Blocks.m in Sources */,
34E8940F1C3B9A03001327C8 /* UISearchBar+Blocks.m in Sources */,
34E894181C3B9A03001327C8 /* UITextField+Blocks.m in Sources */,
Expand Down Expand Up @@ -5161,6 +5176,7 @@
34E894961C3B9FC1001327C8 /* QBAssetsCollectionCheckmarkView.m in Sources */,
34E890871C3B89B2001327C8 /* main.m in Sources */,
34E8911E1C3B92AA001327C8 /* MJRefreshAutoStateFooter.m in Sources */,
34300A4C1E30840E000C1FA5 /* MPNavView.m in Sources */,
34E8939A1C3B9A03001327C8 /* NSObject+MKBlockTimer.m in Sources */,
34E891171C3B92AA001327C8 /* MJRefreshAutoFooter.m in Sources */,
3403847C1D47559A00E4A496 /* MPAdaptationFontViewController.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "MPViewControllerLifeCycle.h"
#import "MPMasonryViewController.h"
#import "MPKeyboardViewController.h"
#import "MPNavigationViewController.h"

@interface MPMoreViewController : BaseViewController

Expand Down
8 changes: 7 additions & 1 deletion MobileProject/Main/Preview/Controller/MPMoreViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)viewDidLoad {
self.navigationItem.title=@"功能导航";

if (!self.dataArray) {
self.dataArray=@[@"JSPatch热更新",@"LKDB数据库运用",@"百度地图",@"二维码",@"照片上传",@"照片上传附带进度",@"字体适配机型",@"日志记录",@"列表倒计时",@"H5交互WebViewJavascriptBridge",@"继承BaseViewController运用",@"列表空白页展现",@"省市区三级联动",@"自定义弹出窗",@"YYText富文本实例",@"列表行展开跟回收隐藏",@"常见表单行类型" ,@"人脸识别注册及验证",@"JavaScriptCore运用",@"viewController生命周期",@"Masonry布局实例",@"键盘处理操作"];
self.dataArray=@[@"JSPatch热更新",@"LKDB数据库运用",@"百度地图",@"二维码",@"照片上传",@"照片上传附带进度",@"字体适配机型",@"日志记录",@"列表倒计时",@"H5交互WebViewJavascriptBridge",@"继承BaseViewController运用",@"列表空白页展现",@"省市区三级联动",@"自定义弹出窗",@"YYText富文本实例",@"列表行展开跟回收隐藏",@"常见表单行类型" ,@"人脸识别注册及验证",@"JavaScriptCore运用",@"viewController生命周期",@"Masonry布局实例",@"键盘处理操作",@"自定义导航栏动态显现效果"];
}

//弹出提示
Expand Down Expand Up @@ -221,6 +221,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.navigationController pushViewController:vc animated:YES];
break;
}
case 22:
{
MPNavigationViewController *vc=[[MPNavigationViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
break;
}
default:
break;
}
Expand Down
15 changes: 15 additions & 0 deletions MobileProject/Main/Preview/Controller/MPNavigationViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// MPNavigationViewController.h
// MobileProject 自定义导航动画效果
//
// Created by wujunyang on 2017/1/19.
// Copyright © 2017年 wujunyang. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "BaseViewController.h"
#import "MPNavView.h"

@interface MPNavigationViewController : BaseViewController

@end
163 changes: 163 additions & 0 deletions MobileProject/Main/Preview/Controller/MPNavigationViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//
// MPNavigationViewController.m
// MobileProject
//
// Created by wujunyang on 2017/1/19.
// Copyright © 2017年 wujunyang. All rights reserved.
//

#import "MPNavigationViewController.h"

@interface MPNavigationViewController ()<UITableViewDataSource, UITableViewDelegate,NaViewDelegate>
@property (nonatomic,strong) UITableView *myTableView;
@property(nonatomic,strong)MPNavView *NavView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@property(nonatomic,strong)UIImageView *headImageView;
@property(nonatomic,strong)UIImageView *backgroundImgV;
@property(nonatomic,assign)float backImgHeight;
@property(nonatomic,assign)float backImgWidth;

@end

@implementation MPNavigationViewController

- (void)viewDidLoad {
[super viewDidLoad];

_dataArray =[[NSMutableArray alloc]init];
for (int i = 0; i < 20; i++) {
NSString * string=[NSString stringWithFormat:@"%d",i];
[_dataArray addObject:string];
}

if (!_myTableView) {
_myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,64, Main_Screen_Width, Main_Screen_Height-64) style:UITableViewStylePlain];
_myTableView.showsVerticalScrollIndicator = NO;
_myTableView.showsHorizontalScrollIndicator = NO;
_myTableView.dataSource = self;
_myTableView.delegate = self;
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_myTableView.tableFooterView=[UIView new];
[_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
[self.view addSubview:_myTableView];
}

//背景
UIImage *image=[UIImage imageNamed:@"back"];
_backgroundImgV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 64)];
_backgroundImgV.image=image;
_backgroundImgV.userInteractionEnabled=YES;
[self.view addSubview:_backgroundImgV];
_backImgHeight=_backgroundImgV.frame.size.height;
_backImgWidth=_backgroundImgV.frame.size.width;


//最上层 放最后
self.NavView=[[MPNavView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 64)];
self.NavView.title = @"我的";
self.NavView.color = [UIColor whiteColor];
self.NavView.left_bt_Image = @"left_";
self.NavView.right_bt_Image = @"Setting";
self.NavView.delegate = self;
[self.view addSubview:self.NavView];
}

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

//如果要隐藏NavigationBar
[self changeNavigationBarTranslationY:-64];
}

-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

//如果隐藏NavigationBar,退出去时还得开放出来
[self changeNavigationBarTranslationY:0];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

#pragma mark NaViewDelegate

//左按钮
-(void)NaLeft
{
NSLog(@"左按钮");
}
//右按钮
-(void)NaRight
{
NSLog(@"右按钮");
}

#pragma mark UITableViewDataSource, UITableViewDelegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
NSString *name=self.dataArray[indexPath.row];
cell.textLabel.text=name;
return cell;
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

int contentOffsety = scrollView.contentOffset.y;

if (scrollView.contentOffset.y<=64) {
self.NavView.headBackView.alpha = scrollView.contentOffset.y/64;
self.NavView.left_bt_Image = @"left_";
self.NavView.right_bt_Image = @"Setting";
self.NavView.color = [UIColor whiteColor];

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}else{
self.NavView.headBackView.alpha = 1;

self.NavView.left_bt_Image = @"left";
self.NavView.right_bt_Image = @"Setting_";
self.NavView.color = RGBA(87, 173, 104, 1);
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}
if (contentOffsety<0) {
CGRect rect = _backgroundImgV.frame;
rect.size.height = _backImgHeight-contentOffsety;
rect.size.width = _backImgWidth* (_backImgHeight-contentOffsety)/_backImgHeight;
rect.origin.x = -(rect.size.width-_backImgWidth)/2;
rect.origin.y = 0;
_backgroundImgV.frame = rect;
}else{
CGRect rect = _backgroundImgV.frame;
rect.size.height = _backImgHeight;
rect.size.width = _backImgWidth;
rect.origin.x = 0;
rect.origin.y = -contentOffsety;
_backgroundImgV.frame = rect;

}
}

@end
26 changes: 26 additions & 0 deletions MobileProject/Main/Preview/View/MPNavView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// MPNavView.h
// MobileProject
//
// Created by wujunyang on 2017/1/19.
// Copyright © 2017年 wujunyang. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol NaViewDelegate <NSObject>
@optional
- (void)NaLeft;
- (void)NaRight;
@end

@interface MPNavView : UIView

@property(nonatomic,assign)id<NaViewDelegate>delegate;
@property(nonatomic,strong)UIImageView * headBackView;
@property(nonatomic,strong)NSString * title;
@property(nonatomic,strong)UIColor * color;
@property(nonatomic,strong)NSString * left_bt_Image;
@property(nonatomic,strong)NSString * right_bt_Image;

@end
88 changes: 88 additions & 0 deletions MobileProject/Main/Preview/View/MPNavView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// MPNavView.m
// MobileProject
//
// Created by wujunyang on 2017/1/19.
// Copyright © 2017年 wujunyang. All rights reserved.
//

#import "MPNavView.h"

@interface MPNavView ()

@property(nonatomic,strong)UILabel *label;
@property(nonatomic,strong)UIButton *leftBt;
@property(nonatomic,strong)UIButton *rightBt;

@end

@implementation MPNavView

-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {

self.headBackView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
self.headBackView.backgroundColor=[UIColor whiteColor];

self.headBackView.alpha = 0;

[self addSubview:self.headBackView];

self.leftBt=[UIButton buttonWithType:UIButtonTypeCustom];
self.leftBt.backgroundColor=[UIColor clearColor];
self.leftBt.frame=CGRectMake(5, 20, 44, 44);
[self.leftBt addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.leftBt];

self.backgroundColor=[UIColor clearColor];
self.label=[[UILabel alloc]initWithFrame:CGRectMake(44, 20, frame.size.width-44-44, 44)];
self.label.textAlignment=NSTextAlignmentCenter;
self.label.font = [UIFont systemFontOfSize:18];
[self addSubview:self.label];

self.rightBt = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBt.backgroundColor = [UIColor clearColor];
self.rightBt.frame = CGRectMake(self.frame.size.width-46, 30, 30, 30);
[self.rightBt addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.rightBt];

}
return self;
}
-(void)setLeft_bt_Image:(NSString *)left_bt_Image
{
_left_bt_Image = left_bt_Image;
[self.leftBt setImage:[UIImage imageNamed:_left_bt_Image] forState:UIControlStateNormal];
}
-(void)setRight_bt_Image:(NSString *)right_bt_Image
{
_right_bt_Image = right_bt_Image;
[self.rightBt setImage:[UIImage imageNamed:_right_bt_Image] forState:UIControlStateNormal];
}

-(void)setTitle:(NSString *)title{
_title=title;
self.label.text=title;
}
-(void)setColor:(UIColor *)color{
_color=color;
self.label.textColor=color;
}

//左边
-(void)leftClick{
if ([_delegate respondsToSelector:@selector(NaLeft)] ) {
[_delegate NaLeft];
}
}
//右边
-(void)rightClick{
if ([_delegate respondsToSelector:@selector(NaRight)]) {
[_delegate NaRight];
}
}


@end
Loading

0 comments on commit 3b40025

Please sign in to comment.