- (void)creatSwipeGesture {
UISwipeGestureRecognizer *swipeGestureRecognizerLeft = [[UISwipeGestureRecognizer alloc] init];
[swipeGestureRecognizerLeft addTarget:self action:@selector(gestureRecognizerHandleLeft:)];
[swipeGestureRecognizerLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeGestureRecognizerLeft];
UISwipeGestureRecognizer *swipeGestureRecognizerRight = [[UISwipeGestureRecognizer alloc] init];
[swipeGestureRecognizerRight addTarget:self action:@selector(gestureRecognizerHandleRight:)];
[swipeGestureRecognizerRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeGestureRecognizerRight];
}
- (void)gestureRecognizerHandleLeft:(UISwipeGestureRecognizer *)gesture {
CGRect tableViewFrame = _tabelView.frame;
tableViewFrame.origin.x = 0;
CGRect frame = _drawerView.frame;
frame.origin.x = -100;
[UIView animateWithDuration:0.5 animations:^{
_tabelView.frame = tableViewFrame;
_drawerView.frame = frame;
}];
}
- (void)gestureRecognizerHandleRight:(UISwipeGestureRecognizer *)gesture {
CGRect tableViewFrame = _tabelView.frame;
tableViewFrame.origin.x = 100;
CGRect frame = _drawerView.frame;
frame.origin.x = 0;
[UIView animateWithDuration:0.5 animations:^{
_tabelView.frame = tableViewFrame;
_drawerView.frame = frame;
}];
}
- (void)creatDrawerView {
_selectString = @"亚洲";
_drawerView = [[UIView alloc] initWithFrame:CGRectMake(-100, 0, 100, ScreenSize.height- 64)];
UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, ScreenSize.height- 64)];
backLabel.backgroundColor = [UIColor lightGrayColor];
backLabel.alpha = 0.5;
[_drawerView addSubview:backLabel];
NSArray *countryNames = @[@"亚洲",@"欧洲",@"北美洲",@"南美洲",@"大洋洲",@"非洲",@"专题"];
for (int i = 0; i < countryNames.count; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(0, (61)*i, 100, 60);
button.backgroundColor = [UIColor clearColor];
[button setTitle:countryNames[i] forState:UIControlStateNormal];
UIImageView *lineView = [[UIImageView alloc] initWithFrame:CGRectMake(5, (60+1)*i, 90, 1)];
lineView.image = [UIImage imageNamed:@"cut_off_rule"];
[_drawerView addSubview:lineView];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:17];
button.tag = 101+i;
[button addTarget:self action:@selector(drawerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[_drawerView addSubview:button];
}
[self.view addSubview:_drawerView];
}
- (void)drawerButtonClick:(UIButton *)button {
[_currentDataArr removeAllObjects];
[_cellDataArr removeAllObjects];
[_countryNameArr removeAllObjects];
_selectString = button.currentTitle;
for (GuideModel *model in _dataArr) {
//亚洲 欧洲 ...
if ([model.category_title isEqualToString:_selectString]) {
//NSLog(@"****%@",_selectString);
//NSLog(@"%@",model);
[_currentDataArr addObject:model];
}
}
for (int i = 0; i < _currentDataArr.count; i++) {
GuideModel *model = _currentDataArr[i];
//不包含则添加 印度 日本 ...
if(![_countryNameArr containsObject:model.country_name_cn]){
//NSLog(@"%@",model.country_name_cn);
[_countryNameArr addObject:model.country_name_cn];
}
}
for (int i = 0; i < _countryNameArr.count; i++) {
NSMutableArray *tmpArr = [[NSMutableArray alloc] init];
for (GuideModel *model in _currentDataArr) {
if ([model.country_name_cn isEqualToString:_countryNameArr[i]]) {
//巴西 秘鲁 . . .
//NSLog(@"%@",model.country_name_cn);
[tmpArr addObject:model];
}
}
[_cellDataArr addObject:tmpArr];
}
[_tabelView reloadData];
}