ProductLibraryViewController.m 6.98 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1
//
2
//  ProductLibraryViewController.m
曹云霄's avatar
曹云霄 committed
3 4
//  Lighting
//
5
//  Created by 曹云霄 on 16/5/4.
曹云霄's avatar
曹云霄 committed
6 7 8
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

9
#import "ProductLibraryViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "ProductCollectionViewCell.h"
曹云霄's avatar
曹云霄 committed
11
#import "ProductDetailsViewController.h"
曹云霄's avatar
曹云霄 committed
12 13 14
#import "ScreeningView.h"
#import "screeningFirstView.h"
#import "screeningSecondView.h"
曹云霄's avatar
曹云霄 committed
15 16


曹云霄's avatar
曹云霄 committed
17
@interface ProductLibraryViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIGestureRecognizerDelegate>
曹云霄's avatar
曹云霄 committed
18

曹云霄's avatar
曹云霄 committed
19 20 21 22
/**
 *  筛选背景框View
 */
@property (nonatomic,strong) ScreeningView *screenView;
曹云霄's avatar
曹云霄 committed
23

曹云霄's avatar
曹云霄 committed
24

曹云霄's avatar
曹云霄 committed
25 26 27 28 29 30 31 32 33
/**
 *  分类View
 */
@property (nonatomic,strong) screeningFirstView *screenFirstView;

/**
 *  筛选View
 */
@property (nonatomic,strong) screeningSecondView *screenSecondView;
曹云霄's avatar
曹云霄 committed
34 35 36

@end

37
@implementation ProductLibraryViewController
曹云霄's avatar
曹云霄 committed
38 39 40 41

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
42
    self.view.backgroundColor = [UIColor blueColor];
曹云霄's avatar
曹云霄 committed
43 44 45
    
    [self uiConfigAction];
    
曹云霄's avatar
曹云霄 committed
46 47
}

曹云霄's avatar
曹云霄 committed
48 49 50 51 52 53 54 55
#pragma mark -布局
- (void)uiConfigAction
{
    self.productCollectionLayout.itemSize = CGSizeMake((ScreenWidth-100)/3, (ScreenWidth-100)/3);
    self.productCollectionLayout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 30);
    self.productCollectionLayout.minimumLineSpacing = 20;
    self.productCollectionLayout.minimumInteritemSpacing = 20;
    self.productCollectionView.dataSource = self;
曹云霄's avatar
曹云霄 committed
56
    self.productCollectionView.delegate = self;
曹云霄's avatar
曹云霄 committed
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
    
    [self CreatescreeningButton];
}



#pragma mark -筛选按钮
- (void)CreatescreeningButton
{
    UIButton *screeningbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    screeningbutton.frame = CGRectMake(ScreenWidth-100, ScreenHeight*6/10, 50, 50);
    
    //阴影层
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(ScreenWidth-97.5, ScreenHeight*6/10+2.5, 45, 45);//保证layer的size比筛选按钮高宽都短5像素
    layer.backgroundColor = [UIColor blackColor].CGColor;
    layer.shadowOffset = CGSizeMake(0, 8);
    layer.shadowOpacity = 0.7;
    layer.cornerRadius = 25;
    [self.view.layer addSublayer:layer];
    
    //筛选按钮
    screeningbutton.layer.masksToBounds = YES;
    screeningbutton.layer.cornerRadius = 25;
    [screeningbutton setTitle:@"筛选" forState:UIControlStateNormal];
    screeningbutton.titleLabel.font = [UIFont systemFontOfSize:15];
    [screeningbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [screeningbutton setTitleColor:kMainBlueColor forState:UIControlStateSelected];
曹云霄's avatar
曹云霄 committed
85
    [screeningbutton addTarget:self action:@selector(ScreeningButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
86 87 88 89 90 91 92 93 94
    screeningbutton.backgroundColor = kMainBlueColor;
    [self.view addSubview:screeningbutton];
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productcell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
95
    
曹云霄's avatar
曹云霄 committed
96 97 98 99 100 101 102 103
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}

曹云霄's avatar
曹云霄 committed
104 105 106 107 108 109 110
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    ProductDetailsViewController *productDetails = [storyboard instantiateViewControllerWithIdentifier:@"productdetails"];
    [self.navigationController pushViewController:productDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
111 112 113



曹云霄's avatar
曹云霄 committed
114 115 116 117 118 119 120
#pragma mark -筛选
- (void)ScreeningButtonClick
{
    self.screenView = [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil]firstObject];
    self.screenView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    self.screenView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    
曹云霄's avatar
曹云霄 committed
121 122
    
    
曹云霄's avatar
曹云霄 committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [self.screenView addGestureRecognizer:tap];
    self.screenView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self.view.window addSubview:self.screenView];
    self.screenView.alpha = 0;
    
    //监听Segmented菜单
    [self.screenView.sortingSegmented addTarget:self action:@selector(sortingSegmentedClick:) forControlEvents:UIControlEventValueChanged];
    
    [self CreateClassificationView];
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.screenView.alpha = 1;
        
    }];
}




曹云霄's avatar
曹云霄 committed
147 148


曹云霄's avatar
曹云霄 committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
#pragma mark -分类、筛选view切换
- (void)sortingSegmentedClick:(UISegmentedControl *)sender {
    
    switch (sender.selectedSegmentIndex) {
        case 0://分类
        {
            NSLog(@"分类");
            [self.screenSecondView removeFromSuperview];
            [self CreateClassificationView];
        }
            break;
        case 1://筛选
        {
            NSLog(@"筛选");
            [self.screenFirstView removeFromSuperview];
            [self CreateScreenSubView];
        }
            break;
            
        default:
            break;
    }
}

曹云霄's avatar
曹云霄 committed
173 174 175



曹云霄's avatar
曹云霄 committed
176 177 178 179 180 181 182 183 184
#pragma mark -创建分类View
- (void)CreateClassificationView
{
    //分类View
    self.screenFirstView = [[[NSBundle mainBundle] loadNibNamed:@"screeningFirstView" owner:self options:nil] firstObject];
    self.screenFirstView.frame = CGRectMake(0, 50, 470, 310);
    [self.screenView.backgroundView addSubview:self.screenFirstView];
}

曹云霄's avatar
曹云霄 committed
185

曹云霄's avatar
曹云霄 committed
186 187 188 189 190 191 192
#pragma mark -创建筛选选项View
- (void)CreateScreenSubView
{
    self.screenSecondView = [[[NSBundle mainBundle] loadNibNamed:@"screeningSecondView" owner:self options:nil] firstObject];
    self.screenSecondView.frame = CGRectMake(0, 50, 470, 310);
    [self.screenView.backgroundView addSubview:self.screenSecondView];
}
曹云霄's avatar
曹云霄 committed
193

曹云霄's avatar
曹云霄 committed
194 195 196 197 198 199 200 201 202 203 204 205 206
#pragma mark -移除筛选框
- (void)DismissScreenView
{
    [UIView animateWithDuration:0.2 animations:^{
        
        self.screenView.alpha = 0;
        
    }completion:^(BOOL finished) {
        
        [self.screenView removeFromSuperview];
        
    }];
}
曹云霄's avatar
曹云霄 committed
207

曹云霄's avatar
曹云霄 committed
208 209 210 211 212 213 214 215 216 217
#pragma mark -UIGestureRecognizerDelegate代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    //取消子视图的的时间穿透,否则子视图的点击无效,会被传递到父视图响应
    if (CGRectContainsPoint(self.screenView.backgroundView.frame, [touch locationInView:self.screenView])) {
        
        return NO;
    }
    return YES;
}
曹云霄's avatar
曹云霄 committed
218 219


曹云霄's avatar
曹云霄 committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end