forked from wujunyang/MobileProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
492 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
MobileProject/Main/Preview/Controller/MPNavigationViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
163
MobileProject/Main/Preview/Controller/MPNavigationViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.