123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- //
- // NY_SelectCView.m
- // 中安生态商城
- //
- // Created by LanSha on 2017/7/25.
- // Copyright © 2017年 王鑫年. All rights reserved.
- //
- #import "SelectView.h"
- #import "UIButton+ImageTitleStyle.h"
- #import "NY_SelectCollectionViewCell.h"
- #import "Masonry.h"
- #import "SelectFiltrateView.h"
- #import <objc/runtime.h>
- #import "OnlyTicketView.h"
- #import "ComprehensiveView.h"
- #ifndef RGBA
- #define RGBA(r,g,b,a) \
- [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
- #endif
- // 屏幕尺寸
- #define KSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
- #define KSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
- // 主色调
- #define MAINCOLOR RGBA(0, 142, 236, 1)
- static NSString *const NY_SelectCollectionViewCellID = @"NY_SelectCollectionViewCell";
- static char *const btnKey = "btnKey";
- static CGFloat filrateHeight = 188;
- @interface SelectView()<SelectFiltrateViewDelegate,selectComViewDelegate>
- {
- BOOL show;
- BOOL comShow;
- }
- @property(nonatomic,strong)ComprehensiveView *compreView;
- @property(nonatomic,strong)NSArray *compreArray;
- @property (nonatomic, strong) SelectFiltrateView *filtrateView;
- @property (nonatomic, strong) NSArray *filtrateArr;
- @end
- @implementation SelectView
- - (instancetype)initWithFrame:(CGRect)frame withArr:(NSArray *)arr{
- self = [super initWithFrame:frame];
- if (self) {
- self.filtrateArr = arr;
- [self initUI];
- }
- return self;
- }
- - (void)initUI{
-
- // [self createCollectionView];
- [self creatFiltrateView];
- self.compreArray = @[@{@"type":@"1",@"title":@"综合排序"},@{@"type":@"6",@"title":@"优惠券面由高到低"}];
- self.backgroundColor = [UIColor yhGrayColor];
-
- UIView *mainView = [UIView new];
- mainView.backgroundColor = RGBA(255, 255, 255, 1);
- [self addSubview:mainView];
- [mainView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(40);
- make.left.right.top.equalTo(self);
- }];
-
- UIView *topLine = [UIView new];
- topLine.backgroundColor = RGBA(222, 222, 222, 1);
- [self addSubview:topLine];
- [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(0.5);
- make.left.right.equalTo(mainView);
- make.top.mas_equalTo(mainView.mas_bottom);
- }];
- NSArray *titleArr = @[@"综合",@"销量",@"价格",@"筛选"];
- for (int i = 0; i < 4; i++) {
- UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(selectClick:) forControlEvents:UIControlEventTouchUpInside];
- [button setTitle:titleArr[i] forState:UIControlStateNormal ];
- button.titleLabel.font = [UIFont systemFontOfSize:13];
- [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [button setTitleColor:[UIColor homeRedColor] forState:UIControlStateSelected];
- [mainView addSubview:button];
- button.tag = 100+i;
-
- [button mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(mainView).offset(KSCREEN_WIDTH/4*i);
- make.top.bottom.equalTo(mainView);
- make.width.mas_equalTo(KSCREEN_WIDTH/4);
- }];
- if (i == _defaultSelectIndex) {
- button.selected = YES;
- }
- if (i == 0) {
- [button setImage:[UIImage imageNamed:@"sort_jt_sel"] forState:UIControlStateNormal];
- [button setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:2];
- _sortBtn = button;
- }
-
- if (i == 2) {
- [button setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/jiagenormal"] forState:UIControlStateNormal];
- [button setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:2];
- objc_setAssociatedObject(button, btnKey, @"1", OBJC_ASSOCIATION_ASSIGN);
- }
- if (i == 3) {
- [button setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/filtrate_n"] forState:UIControlStateNormal];
- [button setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/filtrate_s"] forState:UIControlStateSelected];
- [button setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:2];
- }
-
- }
-
- OnlyTicketView *onlyView = [[OnlyTicketView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, 40)];
- [onlyView.switchBtn addTarget:self action:@selector(onlyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:onlyView];
- [self createComView];
- }
- //只显示优惠券
- - (void)onlyButtonAction:(UIButton *)sender{
- if (self.delegate && [self.delegate respondsToSelector:@selector(selectItme:onlyTicketClick:)]) {
- [self.delegate selectItme:self onlyTicketClick:sender];
- }
- }
- -(void)setSelectItmeArr:(NSArray *)selectItmeArr{
- _selectItmeArr = selectItmeArr;
- _defaultSelectIndex = 0;
- UIButton *button = [self viewWithTag:102];
- [button setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/jiagenormal"] forState:UIControlStateNormal];
- objc_setAssociatedObject(button, btnKey, @"1", OBJC_ASSOCIATION_ASSIGN);
- button.selected = NO;
-
- for (int i = 0; i<4 ;i++) {
- UIButton *button = [self viewWithTag:i+100];
- if (i == 0) {
- button.selected = YES;
- continue;
- }
- if (i == 2) {
- continue;
- }
-
- button.selected = NO;
- if (i == 3) {
- [button setTitle:@"全部" forState:UIControlStateNormal];
- [button setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:2];
- }
- }
-
-
- }
- /**
- 弹出视图
- */
- - (void)creatFiltrateView {
- self.filtrateView = [[SelectFiltrateView alloc] initWithFrame:CGRectMake(0, -filrateHeight, self.width, filrateHeight) filtrateArr:self.filtrateArr];
- self.filtrateView.delegate = self;
- self.filtrateView.hidden = YES;
- [self addSubview:self.filtrateView];
- }
- //综合视图
- -(void)createComView
- {
- self.compreView = [[ComprehensiveView alloc]initWithFrame:CGRectMake(0, -filrateHeight, self.width, 148) CompreensiveArray:self.compreArray];
- self.compreView.delegate=self;
- comShow =YES;
- self.compreView.hidden=YES;
- [self addSubview:self.compreView];
-
- }
- #pragma mark ----------- CompreHensiveViewDelegate ------
- -(void)selectWithBtn:(UIButton *)btn
- {
- NSInteger types =btn.tag/100;
- for (NSDictionary *dics in self.compreArray) {
- if ([dics[@"type"] integerValue] == types) {
- self.compreView.selectDic = dics;
- if ([self.delegate respondsToSelector:@selector(selectItme:sortDic:)]) {
- [self.delegate selectItme:self sortDic:dics];
- }
- [self compreViewsWithBtn:nil];
- return;
- }
- }
- }
- #pragma mark ----------- SelectFiltrateViewDelegate ------
- /**
- 筛选确定事件
- */
- - (void)makeSureActionWithFromValue:(NSString *)fromValue toValue:(NSString *)toValue {
- UIButton *btn = (UIButton *)[self viewWithTag:103];
- if ((fromValue.integerValue > 0) && (toValue.integerValue > fromValue.integerValue) &&(toValue.integerValue > 0)) {
- [btn setTitle:[NSString stringWithFormat:@"%@-%@",fromValue,toValue] forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- }else if (fromValue.integerValue == 0 && toValue.integerValue > 0){
- [btn setTitle:[NSString stringWithFormat:@"%@以下",toValue] forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- }else if (toValue.integerValue < 0 && fromValue.integerValue > 0){
- [btn setTitle:[NSString stringWithFormat:@"%@以上",fromValue] forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- }else {
- [btn setTitle:@"筛选" forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/filtrate_n"] forState:UIControlStateNormal];
- }
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(filtrateViewMakeSureFromValue:toValue:)]) {
- [self.delegate filtrateViewMakeSureFromValue:fromValue toValue:toValue];
- }
-
- [self toggleViewWith:nil];
-
- }
- - (void)selectClick:(UIButton *)btn{
-
- if (btn.tag != 103) {//没点击全部分类,则让其他按钮回复默认状态
- for (int i = 0; i<3 ;i++) {
- UIButton *button = [self viewWithTag:i+100];
- button.selected = NO;
- }
- btn.selected = YES;
- [self toggleViewWith:nil];
- }else{//当点击全部分类按钮,则
-
-
- [self toggleViewWith:btn];
- }
- if (btn.tag == 100) {//综合
- [self compreViewsWithBtn:btn];
- return;
- }else{
- [_sortBtn setImage:[UIImage imageNamed:@"sort_jt"] forState:UIControlStateNormal];
- comShow = YES;
- self.compreView.hidden=comShow;
- self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:!comShow?0.4:0.0];
- }
-
- ButtonClickType type = ButtonClickTypeNormal;
-
- if (btn.tag == 102) {
- NSString *flag = objc_getAssociatedObject(btn, btnKey);
- if ([flag isEqualToString:@"1"]) {
- [btn setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/jiageup"] forState:UIControlStateNormal];
- objc_setAssociatedObject(btn, btnKey, @"2", OBJC_ASSOCIATION_ASSIGN);
- type = ButtonClickTypeUp;
- }else if ([flag isEqualToString:@"2"]){
- [btn setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/jiagedown"] forState:UIControlStateNormal];
- objc_setAssociatedObject(btn, btnKey, @"1", OBJC_ASSOCIATION_ASSIGN);
- type = ButtonClickTypeDown;
- }
-
- }else{
- //点击全部不复位价格
- if (btn.tag != 103) {
- UIButton *button = [self viewWithTag:102];
- [button setImage:[UIImage imageNamed:@"SelectViewBundle.bundle/jiagenormal"] forState:UIControlStateNormal];
- objc_setAssociatedObject(button, btnKey, @"1", OBJC_ASSOCIATION_ASSIGN);
- type = ButtonClickTypeNormal;
- }
- }
- if (btn.tag != 103) {
- if ([self.delegate respondsToSelector:@selector(selectTopButton:withIndex:withButtonType:)]) {
- [self.delegate selectTopButton:self withIndex:btn.tag-100 withButtonType:type];
- }
- }
-
- }
- -(void)compreViewsWithBtn:(UIButton *)btn
- {
- comShow = !comShow;
- self.compreView.hidden=comShow;
- if (!comShow) {
- self.frame = CGRectMake(0, self.frame.origin.y, KSCREEN_WIDTH, SCREEN_HEIGHT);
- [self.sortBtn setImage:[UIImage imageNamed:@"sort_jt_up"] forState:UIControlStateNormal];
-
- }else{
- self.frame = CGRectMake(0, self.frame.origin.y, KSCREEN_WIDTH, 80);
- [self.sortBtn setImage:[UIImage imageNamed:@"sort_jt_sel"] forState:UIControlStateNormal];
-
- }
- float frameY =40;
- [UIView animateWithDuration:0.5 animations:^{
- self.compreView.frame = CGRectMake(0, frameY, KSCREEN_WIDTH, 80);
- self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:!comShow?0.4:0.0];
- }];
-
- }
- //筛选
- - (void)toggleViewWith:(UIButton *)btn{
-
- if (!btn) {
- btn = [self viewWithTag:103];
- if (show) {
- show = NO;
- }else{
- return;
- }
- }else{
- show = !show;
- }
- if (_defaultSelectItmeIndex != 0) {
- btn.selected = YES;
- }else{
- btn.selected = NO;
- }
- if (show) {
- self.frame = CGRectMake(0, self.frame.origin.y, KSCREEN_WIDTH, SCREEN_HEIGHT);
- }else{
- self.frame = CGRectMake(0, self.frame.origin.y, KSCREEN_WIDTH, 80);
- }
- float frameY = show?80:-self.filtrateView.height;
- self.filtrateView.hidden = !show;
- [UIView animateWithDuration:0.5 animations:^{
- self.filtrateView.frame = CGRectMake(0, frameY, KSCREEN_WIDTH, filrateHeight);
- self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:show?0.4:0.0];
- }];
-
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self toggleViewWith:nil];
- if (!comShow) {
- [self compreViewsWithBtn:nil];
- }
-
- }
- //综合弹出视图
- -(void)createComprehensiveView
- {
-
- }
- @end
|