apple1
2018-03-23 c2a34841a7c23752c584558c61227de07ecb6aa8
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
//
//  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 "PublishGoodsViewController.h"
#import "MyRegardController.h"
#import "Share.h"
#import "UIButton+YYWebImage.h"
#import "LoggingViewController.h"
#import "Personal_informationViewController.h"
@interface LeftViewController ()<UITableViewDelegate,UITableViewDataSource>{
    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 NSLayoutConstraint *MarkToMain;//这个的值为宽度的四分之一
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *LeftbackgroundH;//根据图片比例设置高
 
@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)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    
    //确定视图的位置
    self.MarkToMain.constant=0;
    self.LeftbackgroundH.constant=141;
    //头像绘圆
    self.LeftImageIcon.layer.cornerRadius=self.LeftImageIcon.frame.size.height/2;
    self.LeftImageIcon.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];
        [self.navigationController pushViewController:Personal_informationVC animated:YES];
    }else{//跳入登录界面
        LoggingViewController *loginVC=[[LoggingViewController alloc] init];
        [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:{
            CollectionController * cc = [CollectionController new];
            [cc setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:cc animated:YES];
        }
            break;
        case 1:{
            LookNoteController * note = [LookNoteController new];
            [note setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:note animated:YES];
 
        }
            break;
        case 2:{
            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 3:{
            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 4:{//分享
            [Share shareAPP:self.navigationController];
        }
            break;
//        case 5:{//发布东西
//            PublishGoodsViewController *PublishGoodsVC=[[PublishGoodsViewController alloc] init];
//            [nav pushViewController:PublishGoodsVC animated:YES];
//        }
//            break;
        case 5:{
            //帮助与反馈
            HelpViewController *Help = [HelpViewController new];
            [Help setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:Help animated:YES];
        }
            break;
        case 6:{
            //设置
            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){//如果当前状态是登录状态
        [self.LeftImageIcon setContentMode:UIViewContentModeScaleAspectFill];
        [self.LeftImageIcon yy_setImageWithURL:[[NSUserDefaults standardUserDefaults] objectForKey:@"iconURL"]
                                      forState:UIControlStateNormal
                                   placeholder:[UIImage imageNamed:@"用户默认"]];
        [self.LeftLoginBtn setTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"QQUserName"] forState:UIControlStateNormal];
        
    }else{//当前状态为未登录状态
        [self.LeftImageIcon setImage:[UIImage imageNamed:@"用户默认"] forState:UIControlStateNormal];
        [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 == 3){
        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)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end