澎湃iPad上线版本

topicListTopView.m 8.3KB

    // // topicListTopView.m // ThePaperHD // // Created by liyuan on 15/7/2. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicListTopView.h" #import "categoryView.h" #import "topicListViewModel.h" @interface topicListTopView()<categoryDelegate,topicListViewDelegate>{ NSMutableArray *viewList; NSString *sort; } @property(nonatomic, strong)UIView *line; @property(nonatomic, strong)UIButton *hotBtn; @property(nonatomic, strong)UIButton *lasterBtn; @property(nonatomic, strong)UIView *filterLine; @property(nonatomic, strong)NSString *category; @property(nonatomic, strong)topicListViewModel *listViewModel; @end @implementation topicListTopView @synthesize dataList = _dataList; @synthesize category; -(instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { sort = @"1"; self.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; [self addSubview:self.filterView]; [self addSubview:self.line]; self.listViewModel.delegate = self; [self.filterView addSubview:self.hotBtn]; [self.filterView addSubview:self.lasterBtn]; [self.filterView addSubview:self.filterLine]; [self.line makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@19); make.width.equalTo(@42); make.bottom.equalTo(self.bottom).offset(1); make.height.equalTo(@1); }]; } return self; } #pragma mark -- view -(UIView *)line{ if (!_line) { _line = [[UIView alloc] init]; _line.backgroundColor = [UIColor colorWithHexString:BLUECOLOR]; } return _line; } #pragma mark -- data; -(void)setDataList:(NSMutableArray *)data{ _dataList = data; viewList = [NSMutableArray array]; for (int i =0 ;i < _dataList.count; i++) { categoryView *cateView = [[categoryView alloc]initWithFrame:CGRectZero]; [self addSubview:cateView]; if (i ==0) { cateView.isSelect = YES; } [viewList addObject:cateView]; } } #pragma mark -- layout - (void)layoutSubviews { categoryView *forwardView = [[categoryView alloc] initWithFrame:CGRectZero]; for (int i =0; i < viewList.count; i++) { categoryView *cateView = viewList[i]; cateView.cateDelegate =self; cateView.cateBo = _dataList[i]; [cateView makeConstraints:^(MASConstraintMaker *make) { if (i ==0) { make.left.equalTo(self.left); }else{ make.left.equalTo(forwardView.right); } make.top.equalTo(self.top); make.width.equalTo(@80); make.height.equalTo(self.height); }]; forwardView = cateView; } [self.filterView makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.right).offset(-10); make.width.equalTo(@100); make.top.equalTo(self.top); make.bottom.equalTo(self.bottom); }]; [self.hotBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.width.equalTo(40); make.top.equalTo(@0); make.height.equalTo(@55); }]; [self.filterLine makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.hotBtn.right); make.width.equalTo(1); make.top.equalTo(@21); make.height.equalTo(@13); }]; [self.lasterBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.filterLine.right); make.width.equalTo(40); make.top.equalTo(@0); make.height.equalTo(@55); }]; [super layoutSubviews]; } -(UIView *)filterView{ if (!_filterView) { _filterView = [[UIView alloc]init]; _filterView.backgroundColor = [UIColor clearColor]; _filterView.hidden = YES; } return _filterView; } -(UIButton *)hotBtn{ if (!_hotBtn) { _hotBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _hotBtn.titleLabel.font = appFont(13, NO); _hotBtn.selected = YES; [_hotBtn setTitle:@"热门" forState:UIControlStateNormal]; [_hotBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; [_hotBtn setTitleColor:[UIColor colorWithHexString:@"0xc67030"] forState:UIControlStateHighlighted]; [_hotBtn setTitleColor:[UIColor colorWithHexString:@"0xc67030"] forState:UIControlStateSelected]; [_hotBtn addTarget:self action:@selector(hotSelector:) forControlEvents:UIControlEventTouchUpInside]; // _hotBtn.hidden = YES; } return _hotBtn; } -(UIButton *)lasterBtn{ if (!_lasterBtn) { _lasterBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _lasterBtn.titleLabel.font = appFont(13, NO); [_lasterBtn setTitle:@"最新" forState:UIControlStateNormal]; [_lasterBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; [_lasterBtn setTitleColor:[UIColor colorWithHexString:@"0xc67030"] forState:UIControlStateHighlighted]; [_lasterBtn setTitleColor:[UIColor colorWithHexString:@"0xc67030"] forState:UIControlStateSelected]; [_lasterBtn addTarget:self action:@selector(lasterSelector:) forControlEvents:UIControlEventTouchUpInside]; // _lasterBtn.hidden = YES; } return _lasterBtn; } -(UIView *)filterLine{ if (!_filterLine) { _filterLine = [[UIView alloc] init]; _filterLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; // _filterLine.hidden = YES; } return _filterLine; } #pragma mark -- selector -(void) hotSelector:(UIButton *)btn{ sort = @"1"; if(btn.selected){ }else{ btn.selected = !btn.selected; self.lasterBtn.selected = NO; NSMutableDictionary *dic = [NSMutableDictionary dictionary]; if (category) { [dic setObject:@"1" forKey:@"sort"]; [dic setObject:category forKey:@"category"]; }else{ [dic setObject:@"0" forKey:@"sort"]; } if ([self.topicTopDelegate respondsToSelector:@selector(hotAndLaster:)]) { [self.topicTopDelegate hotAndLaster:dic]; } } } -(void) lasterSelector:(UIButton*)btn{ sort = @"0"; if(btn.selected){ }else{ btn.selected = !btn.selected; self.hotBtn.selected = NO; NSMutableDictionary *dic = [NSMutableDictionary dictionary]; if (category) { [dic setObject:@"0" forKey:@"sort"]; [dic setObject:category forKey:@"category"]; }else{ [dic setObject:@"0" forKey:@"sort"]; } if ([self.topicTopDelegate respondsToSelector:@selector(hotAndLaster:)]) { [self.topicTopDelegate hotAndLaster:dic]; } } } #pragma mark -- delegate -(void)changeTextColor:(categoryBO *)bo{ [MobClick event:@"52"];//【需求】统计-iPad(bug:4571) categoryBO *cateBo = bo; if ([cateBo.name isEqualToString:@"精选"]) { self.filterView.hidden = YES; }else{ self.filterView.hidden = NO; } for (int i =0 ; i < viewList.count; i++) { categoryView *cateView = viewList[i]; if ([cateView.chineseName.text isEqualToString:cateBo.name]) { category = cateBo.category; if ([self.topicTopDelegate respondsToSelector:@selector(categoryName:viewList:sort:)]) { [self.topicTopDelegate categoryName:cateBo viewList:viewList sort:sort]; } [UIView animateWithDuration:0.6 animations:^{ cateView.isSelect = YES; } completion:^(BOOL finished) { [UIView animateWithDuration:1.2 animations:^{ [self.line remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(cateView.left).offset(19); make.width.equalTo(@42); make.bottom.equalTo(self.bottom).offset(1); make.height.equalTo(@1); }]; } completion:^(BOOL finished) { }]; }]; }else{ [UIView animateWithDuration:0.6 animations:^{ cateView.isSelect = NO; } completion:^(BOOL finished) { }]; } } } @end