developer
2023-10-31 c2c0b4f016502c4d1e3a3d63854d800521374f6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
//
//  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 <SafariServices/SafariServices.h>
 
@interface LeftViewController ()<UITableViewDelegate,UITableViewDataSource,HXEasyCustomShareViewDelegate>{
    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;
    if(@available(iOS 13.0,*)){
        self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
}
 
- (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;
    _LeftTableView.backgroundColor = [UIColor whiteColor];
    
    //隐藏Cell之间的线
    _LeftTableView.separatorStyle = UITableViewCellSelectionStyleNone;
    _LeftTableView.scrollEnabled = YES;
    //注册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