// // LeftViewController.m // BuWanVideo2.0 // // Created by weikou on 16/7/29. // Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved. // #import "LeftViewController.h" #import "LeftTableViewCell.h" #import "SettingController.h" #import "SlideMenuController.h" #import "HelpViewController.h" #import "MymessageContrlloer.h" #import "LookNoteController.h" #import "CollectionController.h" #import "BuyVipController.h" //#import "PublishGoodsViewController.h" #import "MyRegardController.h" #import "Share.h" #import "UIButton+YYWebImage.h" #import "LoggingViewController.h" #import "Personal_informationViewController.h" #import @interface LeftViewController (){ NSArray *_iconArr; NSArray *_dataArr; } @property (weak, nonatomic) IBOutlet UIImageView *LeftBackGroundView;//侧滑栏的头背景 @property (weak, nonatomic) IBOutlet UITableView *LeftTableView;//侧滑栏的列表 @property (weak, nonatomic) IBOutlet UIButton *LeftImageIcon;//侧滑栏的头像 @property (weak, nonatomic) IBOutlet UIButton *LeftLoginBtn;//立即登录 @property (weak, nonatomic) IBOutlet UIImageView *headerImageview; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *MarkToMain;//这个的值为宽度的四分之一 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *LeftbackgroundH;//根据图片比例设置高 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageBGTopSpace; @property (nonatomic, assign) BOOL userOnLine;//用户是否登录 @end @implementation LeftViewController - (instancetype)init { self = [super init]; if (self) { self.title = @"我的"; // UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:self.title image:[UIImage imageNamed:@"User-拷贝"] selectedImage:[UIImage imageNamed:@"User"]]; // //item.titlePositionAdjustment = UIOffsetMake(0, -5); // self.tabBarItem = item; } return self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; self.navigationController.navigationBar.translucent = NO; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; self.imageBGTopSpace.constant = kStatusBarH + ALNavBarH; //确定视图的位置 self.MarkToMain.constant=0; self.LeftbackgroundH.constant=141; //头像绘圆 self.headerImageview.layer.cornerRadius=self.headerImageview.frame.size.height/2; self.headerImageview.layer.masksToBounds= YES; //tabelView的配置 _LeftTableView.delegate=self; _LeftTableView.dataSource=self; //隐藏Cell之间的线 _LeftTableView.separatorStyle = UITableViewCellSelectionStyleNone; _LeftTableView.scrollEnabled = NO; //注册tableViewCell [_LeftTableView registerNib:[UINib nibWithNibName:@"LeftTableViewCell" bundle:nil] forCellReuseIdentifier:@"LeftTableViewCellId"]; //设置 [self creatData]; //设置侧滑栏的头背景 // _LeftBackGroundView.image=[UIImage imageNamed:@"图层-2"]; //设置立即登录的button [_LeftLoginBtn setTitleColor:kGlobalYellowColor forState:UIControlStateNormal]; [_LeftLoginBtn addTarget:self action:@selector(LoginWithThird) forControlEvents:UIControlEventTouchUpInside]; [_LeftImageIcon addTarget:self action:@selector(LoginWithThird) forControlEvents:UIControlEventTouchUpInside]; //是否登录 [self whetherLogin]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadView) name:@"RELOAD_Message" object:nil]; UIPanGestureRecognizer * drag = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(TouchMove:)]; //拖动 [self.slideMenuController.view addGestureRecognizer:drag]; UILongPressGestureRecognizer * longtouch = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(TouchMove:)]; //长按 [self.slideMenuController.view addGestureRecognizer:longtouch]; } /** 滑动取消侧边栏 */ -(void)TouchMove:(UIGestureRecognizer*)sender{ static CGPoint begin ; switch (sender.state) { case UIGestureRecognizerStateBegan:{ begin = [sender locationInView:self.slideMenuController.view]; break; } case UIGestureRecognizerStateEnded:{ CGPoint end = [sender locationInView:self.slideMenuController.view]; if(begin.x - end.x > 50){ [self.slideMenuController closeLeft]; } break; } default: break; } } //刷新侧边栏 -(void)ReloadView{ [_LeftTableView reloadData]; } /** * 设置 */ -(void)creatData{ if (!_iconArr) { _iconArr=[NSArray arrayWithObjects:@"会员中心",@"我的收藏",@"观看记录",@"我的关注",@"我的消息",@"帮助和反馈",@"隐私政策",@"设置", nil]; } if (!_dataArr) { _dataArr=[NSArray arrayWithObjects:@"会员中心",@"我的收藏",@"观看记录",@"我的关注",@"我的消息",@"帮助与反馈",@"隐私政策",@"设置", nil]; } } /** * 进入登录界面,进行第三方登录 */ -(void)LoginWithThird{ //首先,如果用户已经是登录状态,那么就该跳转到设置界面,让用户可以选择退出登录,如果是未登录的状态,就跳转到登录界面 //首先获取登录状态 _userOnLine= [[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]; if(_userOnLine){//跳入个人中心,目前未实现,暂且空着 Personal_informationViewController *Personal_informationVC=[[Personal_informationViewController alloc] init]; Personal_informationVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:Personal_informationVC animated:YES]; }else{//跳入登录界面 LoggingViewController *loginVC=[[LoggingViewController alloc] init]; loginVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:loginVC animated:YES]; } [self.slideMenuController closeLeft]; } #pragma Mark -UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 45; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; switch (indexPath.row) { case 0:{ if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){//判断用户是否登录 BuyVipController *vc = [[BuyVipController alloc] init]; [vc setHidesBottomBarWhenPushed:YES]; vc.url =[[NSUserDefaults standardUserDefaults] objectForKey:VIPLINK]; [self.navigationController pushViewController:vc animated:YES]; }else{ LoggingViewController *loginVC=[LoggingViewController new]; [loginVC setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:loginVC animated:YES]; } } break; case 1:{ // if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){ // CollectionController * cc = [CollectionController new]; [cc setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:cc animated:YES]; // // }else{ //未登录,引导用户登录 // LoggingViewController *loginVC=[[LoggingViewController alloc] init]; // loginVC.ispresent=YES; // [self presentViewController:loginVC animated:YES completion:^{ // // }]; // } } break; case 2:{ LookNoteController * note = [LookNoteController new]; [note setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:note animated:YES]; } break; case 3:{ if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){//判断用户是否登录 MyRegardController * nr = [MyRegardController new]; [nr setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:nr animated:YES]; }else{ LoggingViewController *loginVC=[LoggingViewController new]; [loginVC setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:loginVC animated:YES]; } } break; case 4:{ if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){//判断用户是否登录 MymessageContrlloer *message = [MymessageContrlloer new]; [message setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:message animated:YES]; }else{ LoggingViewController *loginVC=[LoggingViewController new]; [loginVC setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:loginVC animated:YES]; } } break; case 5:{ //帮助与反馈 HelpViewController *Help = [HelpViewController new]; [Help setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:Help animated:YES]; } break; case 6:{ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api_control_ios.jsp",iconImageUrl]]; SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:url]; // safariVC.delegate = self; // self.navigationController.navigationBarHidden = YES; // [self.navigationController pushViewController:safariVC animated:YES]; // safariVC.title= @"隐私政策"; // safariVC.hidesBottomBarWhenPushed = YES; // 建议 // [self.navigationController pushViewController:safariVC animated:YES]; safariVC.modalPresentationStyle = 0; [self presentViewController:safariVC animated:YES completion:nil]; } break; case 7:{ //设置 SettingController * setting = [SettingController new]; [setting setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:setting animated:YES]; } break; } [self.slideMenuController closeLeft]; } /** * 当前是否登录 */ -(void)whetherLogin{ //调整头像和用户名 [self loadDATA]; //添加一个观察者监听登录和退出登录 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadDATA) name:@"RELOAD_DATA" object:nil]; } /** * 响应登录监听方法的函数 */ -(void)loadDATA{ //重新获取登录状态 _userOnLine= [[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]; if(_userOnLine){//如果当前状态是登录状态 NSString *portrait =[[NSUserDefaults standardUserDefaults] stringForKey:@"iconURL"]; [self.headerImageview setYthImageWithURL:portrait placeholderImage:[UIImage imageNamed:@"用户默认"]]; [self.LeftLoginBtn setTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"QQUserName"] forState:UIControlStateNormal]; }else{//当前状态为未登录状态 self.headerImageview.image = [UIImage imageNamed:@"用户默认"] ; [self.LeftLoginBtn setTitle:@"立即登录" forState:UIControlStateNormal]; } } #pragma Mark -UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ LeftTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"LeftTableViewCellId"]; cell.Icon.image=[UIImage imageNamed:_iconArr[indexPath.row]]; cell.titleText.text=_dataArr[indexPath.row]; //当有新消息时,显示小红点 if(indexPath.row == 4){ if([[NSUserDefaults standardUserDefaults] boolForKey:@"HaveMessage"]){ UIView * red = [[UIView alloc]initWithFrame:CGRectMake(cell.titleText.frame.origin.x + 100, 21, 8, 8)]; red.backgroundColor = [UIColor redColor]; red.layer.cornerRadius = 4; red.layer.masksToBounds = YES; [cell addSubview:red]; } } return cell; } - (void)shareAPP{//分享响应 标题 内容 分享链接 NSMutableArray *shareAry=[NSMutableArray array]; if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) { NSArray *QQArr=@[@{@"image":@"newqq",@"title":@"QQ"},@{@"image":@"newqq空间",@"title":@"QQ空间"}]; [shareAry addObjectsFromArray:QQArr]; } if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]){ NSArray *WXArr=@[@{@"image":@"new微信",@"title":@"微信"},@{@"image":@"new朋友圈",@"title":@"朋友圈"}]; [shareAry addObjectsFromArray:WXArr]; } if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sinaweibo://"]]){ NSArray *XLArr=@[@{@"image":@"new微博",@"title":@"新浪微博"}]; [shareAry addObjectsFromArray:XLArr]; } UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 54)]; headerView.backgroundColor = [UIColor clearColor]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, headerView.frame.size.width, 15)]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blackColor]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont systemFontOfSize:15]; label.text = @"分享到"; [headerView addSubview:label]; UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headerView.frame.size.height-0.5, headerView.frame.size.width, 0.5)]; lineLabel.backgroundColor = [UIColor colorWithRed:208/255.0 green:208/255.0 blue:208/255.0 alpha:1.0]; [headerView addSubview:lineLabel]; UILabel *lineLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.width, 0.5)]; lineLabel1.backgroundColor = [UIColor colorWithRed:208/255.0 green:208/255.0 blue:208/255.0 alpha:1.0]; HXEasyCustomShareView *shareView = [[HXEasyCustomShareView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)]; shareView.backView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]; shareView.headerView = headerView; float height = [shareView getBoderViewHeight:shareAry firstCount:0]; shareView.boderView.frame = CGRectMake(0, 0, shareView.frame.size.width, height); shareView.middleLineLabel.hidden = YES; [shareView.cancleButton addSubview:lineLabel1]; shareView.cancleButton.frame = CGRectMake(shareView.cancleButton.frame.origin.x, shareView.cancleButton.frame.origin.y, shareView.cancleButton.frame.size.width, 54); shareView.cancleButton.titleLabel.font = [UIFont systemFontOfSize:16]; [shareView.cancleButton setTitleColor:[UIColor colorWithRed:184/255.0 green:184/255.0 blue:184/255.0 alpha:1.0] forState:UIControlStateNormal]; [shareView setShareAry:shareAry delegate:self]; [self.view addSubview:shareView]; } #pragma mark -HXEasyCustomShareViewDelegate //- (void)easyCustomShareViewButtonAction:(HXEasyCustomShareView *)shareView title:(NSString *)title { // if ([title isEqualToString:@"微信"]) { // [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession]; // }else if ([title isEqualToString:@"朋友圈"]) { // [self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine]; // }else if ([title isEqualToString:@"QQ"]) { // [self shareWebPageToPlatformType:UMSocialPlatformType_QQ]; // }else if ([title isEqualToString:@"新浪微博"]) { // [self shareWebPageToPlatformType:UMSocialPlatformType_Sina]; // }else if ([title isEqualToString:@"QQ空间"]) { // [self shareWebPageToPlatformType:UMSocialPlatformType_Qzone]; // }else{ // //到这里就错了 // } // [shareView tappedCancel]; //} /** 分享 */ //- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType{ // // //创建分享消息对象 // UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; // // //创建网页内容对象 // UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"布丸影视大全" descr:[NSString stringWithFormat:@"%@!%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareContent"],[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]] thumImage:[UIImage imageNamed:@"分享图标"]]; // NSLog(@"%@---%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareContent"],[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]); // //设置网页地址 // shareObject.webpageUrl =[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]; // NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]); // //分享消息对象设置分享内容对象 // messageObject.shareObject = shareObject; // NSLog(@"%@",shareObject); // //调用分享接口 // [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) { // if (error) { // [SVProgressHUD showErrorWithStatus:@"分享失败!"]; // NSLog(@"************Share fail with error %@*********",error); // }else{ // NSLog(@"response data is %@",data); // } // }]; //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end