//
|
// LinPullMainViewController.m
|
// LINPullTableView
|
//
|
// Created by earnestLin on 2019/1/16.
|
// Copyright © 2019年 earnestLin. All rights reserved.
|
//
|
|
#import "LinPullMainViewController.h"
|
|
#import "LinPullTopViewController.h"
|
#import "LinPullBottomViewController.h"
|
#import "PBLoginViewController.h"
|
#import "PBTabBarController.h"
|
// tool
|
#import "JYPulleyViewController.h"
|
#import "PBProjectInfoView.h"
|
#import "PBSetViewController.h"
|
#import "PBScanningViewController.h"
|
#import "PBMessageController.h"
|
#import "PBNavigationController.h"
|
@interface LinPullMainViewController ()<LinPullBottomViewControllerDelegate>
|
|
@property (nonatomic, strong) JYPulleyViewController *pulleyViewController;
|
@property (nonatomic, strong) LinPullTopViewController *topController;
|
@property (nonatomic, strong) LinPullBottomViewController *bottomController;
|
@property (nonatomic, weak) UIButton *allProjectBtn;
|
@property (nonatomic, weak) UIButton *collectionProjectBtn;
|
@property (nonatomic, strong) PBProjectInfoView *projectInfoView;
|
@end
|
|
@implementation LinPullMainViewController
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[PBNoteCenter addObserver:self selector:@selector(reRegister) name:@"PBNoteCenterTokenExpired" object:nil];
|
self.view.backgroundColor = [UIColor whiteColor];
|
if ([NSString getLoginData]) {
|
[self setupUI];
|
}else{
|
[self toLogin];
|
}
|
}
|
- (void)reRegister {
|
[self toLogin];
|
}
|
- (void)toLogin {
|
// self.dataList = nil;
|
// [self.tableView reloadData];
|
PBLoginViewController *loginVC = [[PBLoginViewController alloc] init];
|
loginVC.LoginSuccessfulBlock = ^{
|
// self.mineView.realName = Realname;
|
// self.searchBar.text = nil;
|
// self.fullName = nil;
|
// [self.tableView.mj_header beginRefreshing];
|
[self setupUI];
|
};
|
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
[self presentViewController:loginVC animated:YES completion:nil];
|
}
|
- (void)viewWillAppear:(BOOL)animated
|
{
|
[super viewWillAppear:animated];
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
|
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated
|
{
|
[super viewWillDisappear:animated];
|
|
// self.navigationController.navigationBarHidden = NO;
|
}
|
|
#pragma mark - setupUI
|
- (void)setupUI {
|
self.title = @"amap";
|
__weak typeof(self) weakSelf = self;
|
self.topController = [[LinPullTopViewController alloc] init];
|
self.topController.OpenDetailsBlock = ^(PBProjectModel * _Nonnull projectModel) {
|
[PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusClosed]];
|
weakSelf.projectInfoView.projectModel = projectModel;
|
weakSelf.projectInfoView.IntoProjectBlock = ^(PBProjectModel * _Nonnull projectModel){
|
PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
|
tabBarController.projectModel = projectModel;
|
tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
|
[weakSelf presentViewController:tabBarController animated:YES completion:nil];
|
};
|
[weakSelf show];
|
};
|
self.topController.ShutDetailsBlock = ^{
|
[weakSelf hidden];
|
};
|
self.bottomController = [[LinPullBottomViewController alloc] init];
|
self.bottomController.jumpToSetVCBlock = ^{
|
PBSetViewController *setVC = [[PBSetViewController alloc] init];
|
setVC.ToLoginBlock = ^{
|
[weakSelf.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
[weakSelf toLogin];
|
};
|
[weakSelf.navigationController pushViewController:setVC animated:YES];
|
};
|
self.bottomController.jumpToMessageBlock = ^{
|
PBMessageController *messageVC = [[PBMessageController alloc] init];
|
PBNavigationController *nav = [[PBNavigationController alloc] initWithRootViewController:messageVC];
|
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
[weakSelf presentViewController:nav animated:YES completion:nil];
|
// [weakSelf.navigationController pushViewController:messageVC animated:YES];
|
};
|
self.bottomController.delegate = self;
|
self.pulleyViewController =
|
[[JYPulleyViewController alloc] initWithContentDataSource:self.topController
|
drawerDataSource:self.bottomController];
|
self.pulleyViewController.view.frame = self.view.bounds;
|
self.pulleyViewController.supportedStatus = JYPulleyStatusClosed | JYPulleyStatusExpand | JYPulleyStatusPartiallyExpand;
|
self.pulleyViewController.drawerExpandTopInset = 0;
|
self.pulleyViewController.dimmingView.backgroundColor = [UIColor whiteColor];
|
self.pulleyViewController.dimmingOpacity = 1;
|
self.pulleyViewController.drawerDelegate = self.bottomController;
|
self.bottomController.drawerScrollDelegate = self.pulleyViewController;
|
[self.pulleyViewController addChildViewController:self.topController];
|
[self.pulleyViewController addChildViewController:self.bottomController];
|
[self addChildViewController:self.pulleyViewController];
|
[self.view addSubview:self.pulleyViewController.view];
|
[self.pulleyViewController updateStatus:JYPulleyStatusPartiallyExpand animated:NO];
|
CGFloat bottomSpacing = 0.f;
|
if (IS_IPHONE_X) {
|
bottomSpacing = IPHONE_X_BOTTOM;
|
}
|
// UIImageView *bottomV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_bar"]];
|
// [self.view addSubview:bottomV];
|
// [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
|
// make.left.right.equalTo(self.view);
|
// make.height.equalTo(@71);
|
// make.bottom.equalTo(self.view).offset(-bottomSpacing);
|
// }];
|
UIView *bottomV = [[UIView alloc] init];
|
bottomV.backgroundColor = [UIColor whiteColor];
|
[self.view addSubview:bottomV];
|
[bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.right.equalTo(self.view);
|
make.height.equalTo(@56);
|
make.bottom.equalTo(self.view).offset(-bottomSpacing);
|
}];
|
|
UIView *supplementV = [[UIView alloc] init];
|
supplementV.backgroundColor = [UIColor whiteColor];
|
[self.view addSubview:supplementV];
|
[supplementV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV.mas_bottom);
|
make.left.right.equalTo(bottomV);
|
make.bottom.equalTo(self.view);
|
}];
|
// UIButton *scanningBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"scan"]];
|
// [scanningBtn addTarget:self action:@selector(scanningAction) forControlEvents:UIControlEventTouchUpInside];
|
// [self.view addSubview:scanningBtn];
|
// [scanningBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
// make.top.equalTo(bottomV).offset(10);
|
// make.centerX.equalTo(bottomV);
|
// make.size.mas_equalTo(CGSizeMake(44, 44));
|
// }];
|
UIButton *allProjectBtn = [UIButton z_bgNormalImage:[UIImage imageNamed:@"all_project_nor"] bgSelectedImage:[UIImage imageNamed:@"all_project"]];
|
allProjectBtn.selected = YES;
|
[allProjectBtn addTarget:self action:@selector(allProjectAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:allProjectBtn];
|
[allProjectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV).offset(12);
|
make.left.equalTo(bottomV).offset(63);
|
make.size.mas_equalTo(CGSizeMake(28, 42));
|
}];
|
|
UIButton *collectProjectBtn = [UIButton z_bgNormalImage:[UIImage imageNamed:@"collect_nor"] bgSelectedImage:[UIImage imageNamed:@"collect_select"]];
|
[collectProjectBtn addTarget:self action:@selector(collectionProjectAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:collectProjectBtn];
|
[collectProjectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV).offset(12);
|
make.right.equalTo(bottomV).offset(-63);
|
make.size.mas_equalTo(CGSizeMake(28, 42));
|
}];
|
self.allProjectBtn = allProjectBtn;
|
self.collectionProjectBtn = collectProjectBtn;
|
[self.view addSubview:self.projectInfoView];
|
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.projectInfoView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
|
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
|
maskLayer.frame = self.projectInfoView.bounds;
|
maskLayer.path = maskPath.CGPath;
|
self.projectInfoView.layer.mask = maskLayer;
|
}
|
|
#pragma mark - 扫描二维码
|
- (void)scanningAction {
|
PBScanningViewController *scanningVC = [[PBScanningViewController alloc] init];
|
[self QRCodeScanVC:scanningVC];
|
}
|
- (void)QRCodeScanVC:(UIViewController *)scanVC {
|
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
if (device) {
|
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
switch (status) {
|
case AVAuthorizationStatusNotDetermined: {
|
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
if (granted) {
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
[self.navigationController pushViewController:scanVC animated:YES];
|
});
|
NSLog(@"用户第一次同意了访问相机权限 - - %@", [NSThread currentThread]);
|
} else {
|
NSLog(@"用户第一次拒绝了访问相机权限 - - %@", [NSThread currentThread]);
|
}
|
}];
|
break;
|
}
|
case AVAuthorizationStatusAuthorized: {
|
[self.navigationController pushViewController:scanVC animated:YES];
|
break;
|
}
|
case AVAuthorizationStatusDenied: {
|
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
|
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
}];
|
|
[alertC addAction:alertA];
|
[self presentViewController:alertC animated:YES completion:nil];
|
break;
|
}
|
case AVAuthorizationStatusRestricted: {
|
NSLog(@"因为系统原因, 无法访问相册");
|
break;
|
}
|
|
default:
|
break;
|
}
|
return;
|
}
|
|
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
|
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
}];
|
|
[alertC addAction:alertA];
|
[self presentViewController:alertC animated:YES completion:nil];
|
}
|
|
#pragma mark - 全部项目
|
- (void)allProjectAction {
|
if (self.allProjectBtn.selected) {
|
return;
|
}
|
self.collectionProjectBtn.selected = NO;
|
self.allProjectBtn.selected = YES;
|
self.bottomController.isFavorite = NO;
|
}
|
#pragma mark - 收藏项目
|
- (void)collectionProjectAction {
|
if (self.collectionProjectBtn.selected) {
|
return;
|
}
|
self.allProjectBtn.selected = NO;
|
self.collectionProjectBtn.selected = YES;
|
self.bottomController.isFavorite = YES;
|
}
|
#pragma mark - JYEBMonitorEbikeDetailContentVCDelegate
|
|
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
|
// didChangeToExpand:(CGFloat)height
|
//{
|
// self.navigationController.navigationBarHidden = YES;
|
//}
|
//
|
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
|
// didChangeToPartiallyExpand:(CGFloat)height
|
//{
|
// self.navigationController.navigationBarHidden = YES;
|
//}
|
//
|
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
|
// didChangeToClosed:(CGFloat)height
|
//{
|
// self.navigationController.navigationBarHidden = YES;
|
//}
|
- (PBProjectInfoView *)projectInfoView {
|
if (_projectInfoView == nil) {
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 182.f + IPHONE_X_BOTTOM;
|
}else {
|
height = 182.f;
|
}
|
__weak typeof(self) weakSelf = self;
|
_projectInfoView = [[PBProjectInfoView alloc] initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, height)];
|
_projectInfoView.packupBlock = ^{
|
[weakSelf hidden];
|
};
|
weakSelf.projectInfoView.SetCollectionState = ^(PBProjectModel * _Nonnull projectModel) {
|
weakSelf.topController.projectModel = projectModel;
|
};
|
}
|
return _projectInfoView;
|
}
|
- (void)hidden {
|
[UIView animateWithDuration:0.3 animations:^{
|
// self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
self.projectInfoView.y = PBScreenHeight;
|
}completion:^(BOOL finished) {
|
for (UIView *cover in PBKeyWindow.subviews) {
|
if ([cover isKindOfClass:[PBProjectInfoView class]]) {
|
[cover removeFromSuperview];
|
}
|
}
|
}];
|
}
|
- (void)show {
|
[UIView animateWithDuration:0.3 animations:^{
|
// self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 182.f + IPHONE_X_BOTTOM;
|
}else {
|
height = 182.f;
|
}
|
self.projectInfoView.y = PBScreenHeight - height;
|
}];
|
}
|
@end
|