//
|
// LinPullBottomViewController.m
|
// LINPullTableView
|
//
|
// Created by earnestLin on 2019/1/16.
|
// Copyright © 2019年 earnestLin. All rights reserved.
|
//
|
|
#import "LinPullBottomViewController.h"
|
#import "PBProjectModel.h"
|
#import "PBProjectTableViewCell.h"
|
#import "PBProjectSearchView.h"
|
#import "PBTabBarController.h"
|
|
//PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
|
//tabBarController.projectModel = self.dataList[indexPath.row];
|
//tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
|
//[self presentViewController:tabBarController animated:YES completion:nil];
|
static NSString *const cellID = @"cellID";
|
|
//static CGFloat const kBottomControllerClosedHeight = 141.0f;
|
static inline CGFloat kBottomControllerClosedHeight() {
|
if (IS_IPHONE_X) {
|
return 141.0f + IPHONE_X_BOTTOM;
|
}else {
|
return 141.0f;
|
}
|
}
|
static inline CGFloat kBottomControllerPartiallyExpandHeight() {
|
// return [UIScreen mainScreen].bounds.size.height - 336.0f;
|
if (IS_IPHONE_X) {
|
return 300.0f + IPHONE_X_BOTTOM;
|
}else {
|
return 300.0f;
|
}
|
}
|
|
@interface LinPullBottomViewController ()<UITableViewDelegate,UITableViewDataSource>
|
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, strong) NSArray *dataList;
|
@property (nonatomic, weak) UIButton *topBtn;
|
@property (nonatomic, weak) UIView *newsV;
|
@property (nonatomic, assign) JYPulleyStatus lastStatus;
|
@property (nonatomic, assign) JYPulleyStatus currentStatus;
|
@property (nonatomic, strong) PBProjectSearchView *projectSearchV;
|
@end
|
|
@implementation LinPullBottomViewController
|
-(void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
[self loadUnReadMessage];
|
}
|
- (void)loadUnReadMessage {
|
[[PBNetworkTools sharedTools] RequestGetNotReadMsgWithPageIndex:1 andPageSize:1 andIsRead:@"0" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
// [YJProgressHUD showMessage:@"加载失败" inView:nil];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
NSArray *list = [networkModel.Data valueForKey:@"List"];
|
if (list.count > 0) {
|
self.newsV.hidden = NO;
|
}else {
|
self.newsV.hidden = YES;
|
}
|
}else {
|
// [YJProgressHUD showMessage:@"加载失败" inView:nil];
|
}
|
}];
|
}
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[PBNoteCenter addObserver:self selector:@selector(JPushMessage:) name:@"JPushMessage" object:nil];
|
[PBNoteCenter addObserver:self selector:@selector(jumpBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
|
[self setRoundedCorners];
|
[self setupUI];
|
[self loadProjectList];
|
}
|
- (void)JPushMessage:(NSNotification *)notification {
|
self.newsV.hidden = NO;
|
}
|
- (void)jumpBecomeActive:(NSNotification *)notification {
|
[self loadUnReadMessage];
|
}
|
- (void)setRoundedCorners {
|
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
|
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
|
//设置大小
|
maskLayer.frame = self.view.bounds;
|
//设置图形样子
|
maskLayer.path = maskPath.CGPath;
|
self.view.layer.mask = maskLayer;
|
}
|
- (void)loadProjectList {
|
self.dataList = nil;
|
[self.tableView reloadData];
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
NSString *favorite = @"";
|
if (self.isFavorite) {
|
favorite = @"1";
|
}
|
[[PBNetworkTools sharedTools] getProjectListWithKeyword:@"" andIsPublic:@"" andSort:@"CreateDate desc" andSkip:@"0" andtake:@"999" andOnlyFavorite:favorite andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if(error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"加载项目列表失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
self.dataList = [NSArray yy_modelArrayWithClass:[PBProjectModel class] json:[networkModel.Data valueForKey:@"rows"]];
|
[self.tableView reloadData];
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}
|
#pragma mark - setupUI
|
|
- (void)setupUI {
|
self.view.backgroundColor = [UIColor whiteColor];
|
UIButton *topBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"bar"]];
|
[topBtn addTarget:self action:@selector(topBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:topBtn];
|
[topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view).offset(2);
|
make.size.mas_equalTo(CGSizeMake(28, 20));
|
make.centerX.equalTo(self.view);
|
}];
|
UIImageView *searchBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_bg"]];
|
[self.view addSubview:searchBg];
|
[searchBg mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view).offset(24);
|
make.left.equalTo(self.view).offset(10);
|
make.right.equalTo(self.view).offset(-10);
|
make.height.equalTo(@46);
|
}];
|
// UIButton *iconBtn = [[UIButton alloc] init];
|
// iconBtn.backgroundColor = PBColor(38, 55, 75);
|
// [iconBtn addTarget:self action:@selector(iconBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
// [self.view addSubview:iconBtn];
|
// [iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
// make.centerY.equalTo(searchBg);
|
// make.size.mas_equalTo(CGSizeMake(28, 28));
|
// make.left.equalTo(searchBg).offset(10);
|
// }];
|
// [iconBtn circleViewWithRadius:6];
|
|
UIImageView *iconBtn = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_bg"]];
|
iconBtn.userInteractionEnabled = YES;
|
[self.view addSubview:iconBtn];
|
[iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(searchBg);
|
make.size.mas_equalTo(CGSizeMake(28, 28));
|
make.left.equalTo(searchBg).offset(10);
|
}];
|
UITapGestureRecognizer *iconBtnTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconBtnAction)];
|
[iconBtn addGestureRecognizer:iconBtnTap];
|
|
UILabel *nameL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:NO Font:14];
|
nameL.textAlignment = NSTextAlignmentCenter;
|
NSString *name = Realname;
|
BOOL isChiness = [self IsChinese:name];
|
if (isChiness) {
|
nameL.text = [name substringFromIndex:name.length - 1];
|
}else {
|
nameL.text = [name substringToIndex:1];
|
}
|
[self.view addSubview:nameL];
|
[nameL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.bottom.left.right.equalTo(iconBtn);
|
}];
|
|
UIButton *newsBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"news"]];
|
[newsBtn addTarget:self action:@selector(newsBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:newsBtn];
|
[newsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(searchBg);
|
make.size.mas_equalTo(CGSizeMake(24, 24));
|
make.right.equalTo(searchBg).offset(-10);
|
}];
|
UIView *newsV = [[UIView alloc] init];
|
newsV.backgroundColor = [UIColor redColor];
|
[self.view addSubview:newsV];
|
newsV.layer.cornerRadius = 3;
|
[newsV.layer setMasksToBounds:YES];
|
[newsV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.size.mas_equalTo(CGSizeMake(5, 5));
|
make.top.equalTo(newsBtn);
|
make.left.equalTo(newsBtn.mas_right);
|
}];
|
self.newsV = newsV;
|
self.newsV.hidden = YES;
|
|
UILabel *searchTextL = [UILabel z_labelWithText:@"在全部项目中查找" Color:PBColor(97, 111, 125) isBold:NO Font:16];
|
[self.view addSubview:searchTextL];
|
[searchTextL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(searchBg);
|
make.left.equalTo(searchBg).offset(50);
|
make.right.equalTo(newsBtn.mas_left).offset(-10);
|
make.height.equalTo(@40);
|
}];
|
searchTextL.userInteractionEnabled = YES;
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchAction)];
|
[searchTextL addGestureRecognizer:tap];
|
self.topBtn = topBtn;
|
}
|
- (BOOL)IsChinese:(NSString *)str {
|
for(int i=0; i< [str length];i++){
|
int a = [str characterAtIndex:i];
|
if( a > 0x4e00 && a < 0x9fff){
|
return YES;
|
}
|
}
|
return NO;
|
}
|
#pragma mark - 点击顶部按钮
|
- (void)topBtnAction {
|
JYPulleyStatus action = JYPulleyStatusNone;
|
if (self.currentStatus == JYPulleyStatusExpand) {//上
|
action = JYPulleyStatusPartiallyExpand;
|
}else if (self.currentStatus == JYPulleyStatusClosed) {//下
|
action = JYPulleyStatusPartiallyExpand;
|
}else if (self.currentStatus == JYPulleyStatusPartiallyExpand) {//中
|
if (self.lastStatus == JYPulleyStatusExpand) {
|
action = JYPulleyStatusClosed;
|
}else {
|
action = JYPulleyStatusExpand;
|
}
|
}
|
[PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",action]];
|
}
|
#pragma mark - 点击头像方法
|
- (void)iconBtnAction {
|
if (self.jumpToSetVCBlock) {
|
self.jumpToSetVCBlock();
|
}
|
}
|
#pragma mark - 点击消息方法
|
- (void)newsBtnAction {
|
if (self.jumpToMessageBlock) {
|
self.jumpToMessageBlock();
|
}
|
}
|
#pragma mark - 搜索方法
|
- (void)searchAction {
|
__weak typeof(self) weakSelf = self;
|
[PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusExpand]];
|
self.projectSearchV.hidden = NO;
|
self.projectSearchV.cancelSearchBlock = ^{
|
[weakSelf cancelSearchWithDrag:NO];
|
};
|
// PBProjectSearchViewController *projectSearchVC = [[PBProjectSearchViewController alloc] init];
|
//// projectSearchVC.modalPresentationStyle = UIModalPresentationCustom;
|
// projectSearchVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
|
// [self presentViewController:projectSearchVC animated:NO completion:nil];
|
// [self.navigationController pushViewController:projectSearchVC animated:NO];
|
}
|
- (void)cancelSearchWithDrag:(BOOL)drag {
|
[self.view endEditing:NO];
|
[self.projectSearchV removeFromSuperview];
|
self.projectSearchV = nil;
|
if (!drag) {
|
[PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusPartiallyExpand]];
|
}
|
}
|
#pragma mark - JYPulleyDrawerDataSource
|
|
- (CGFloat)closedHeightInPulleyViewController:(JYPulleyViewController *)pulleyViewController
|
{
|
return kBottomControllerClosedHeight();
|
}
|
|
- (CGFloat)partiallyExpandHeightInPulleyViewController:(JYPulleyViewController *)pulleyViewController
|
{
|
return kBottomControllerPartiallyExpandHeight();
|
}
|
|
#pragma mark - JYPulleyDrawerDelegate
|
|
- (void)pulleyViewController:(JYPulleyViewController *)pulleyViewController didChangeStatus:(JYPulleyStatus)status
|
{
|
self.lastStatus = self.currentStatus;
|
self.currentStatus = status;
|
if (status == JYPulleyStatusClosed)
|
{
|
self.tableView.scrollEnabled = NO;
|
// self.tableView.contentInset =
|
// UIEdgeInsetsMake(0, 0, kBottomControllerClosedHeight, 0);
|
|
// if ([self.delegate
|
// respondsToSelector:@selector(linPullBottomViewController:didChangeToClosed:)]) {
|
// [self.delegate linPullBottomViewController:self
|
// didChangeToClosed:kBottomControllerClosedHeight()];
|
// }
|
[self cancelSearchWithDrag:YES];
|
[self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar_arrow"] forState:UIControlStateNormal];
|
}
|
if (status == JYPulleyStatusPartiallyExpand)
|
{
|
self.tableView.scrollEnabled = NO;
|
// self.tableView.contentInset =
|
// UIEdgeInsetsMake(0, 0, kBottomControllerPartiallyExpandHeight(), 0);
|
// if ([self.delegate respondsToSelector:@selector(linPullBottomViewController:didChangeToPartiallyExpand:)])
|
// {
|
// [self.delegate linPullBottomViewController:self didChangeToPartiallyExpand:kBottomControllerPartiallyExpandHeight()];
|
// }
|
[self cancelSearchWithDrag:YES];
|
[self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar"] forState:UIControlStateNormal];
|
}
|
|
if (status == JYPulleyStatusExpand)
|
{
|
self.tableView.scrollEnabled = YES;
|
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
|
// if ([self.delegate respondsToSelector:@selector(linPullBottomViewController:didChangeToPartiallyExpand:)])
|
// {
|
// [self.delegate linPullBottomViewController:self didChangeToExpand:0];
|
// }
|
[self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar_down"] forState:UIControlStateNormal];
|
}
|
}
|
|
#pragma mark - tableViewDelegate
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.dataList.count;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
return 120;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
static NSString *cellId = @"cellId";
|
PBProjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
if (!cell)
|
cell = [[PBProjectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
|
cell.projectModel = self.dataList[indexPath.row];
|
return cell;
|
}
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
|
tabBarController.projectModel = self.dataList[indexPath.row];
|
tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
|
[self presentViewController:tabBarController animated:YES completion:nil];
|
}
|
|
#pragma mark - GET
|
- (UITableView *)tableView {
|
if (!_tableView)
|
{
|
CGFloat bottomViewH = 71.f - 20;
|
if (IS_IPHONE_X) {
|
bottomViewH = bottomViewH + IPHONE_X_BOTTOM;
|
}
|
_tableView = [[UITableView alloc] init];
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
_tableView.delegate = self;
|
_tableView.dataSource = self;
|
[self.view addSubview:_tableView];
|
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view).offset(75 );
|
make.left.right.bottom.equalTo(self.view);
|
make.bottom.equalTo(self.view).offset(-bottomViewH);
|
}];
|
}
|
return _tableView;
|
}
|
- (PBProjectSearchView *)projectSearchV {
|
__weak typeof(self) weakSelf = self;
|
if (!_projectSearchV) {
|
_projectSearchV = [[PBProjectSearchView alloc] init];
|
[self.view addSubview:_projectSearchV];
|
[_projectSearchV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.right.bottom.equalTo(self.view);
|
make.top.equalTo(self.view).offset(24);
|
}];
|
_projectSearchV.hidden = YES;
|
_projectSearchV.projectDetailBlock = ^(PBProjectModel * _Nonnull projectModel) {
|
PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
|
tabBarController.projectModel = projectModel;
|
tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
|
[weakSelf presentViewController:tabBarController animated:YES completion:nil];
|
};
|
}
|
return _projectSearchV;
|
}
|
- (void)setIsFavorite:(BOOL)isFavorite {
|
_isFavorite = isFavorite;
|
[self loadProjectList];
|
}
|
- (void)dealloc {
|
[PBNoteCenter removeObserver:self];
|
}
|
@end
|