SeceneLibraryView.m 11.3 KB
Newer Older
zhu's avatar
zhu committed
1 2 3 4 5 6 7 8 9
//
//  SeceneLibraryView.m
//  Lighting
//
//  Created by mac on 16/5/11.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "SeceneLibraryView.h"
zhu's avatar
zhu committed
10 11 12
@interface SeceneLibraryView ()

@end
zhu's avatar
zhu committed
13 14

@implementation SeceneLibraryView
zhu's avatar
zhu committed
15 16 17 18 19

- (void)viewDidLoad {
            [self initdata];
            [self initView];
    
zhu's avatar
zhu committed
20
}
zhu's avatar
zhu committed
21 22 23 24 25 26 27 28
//- (instancetype)initWithFrame:(CGRect)frame
//{
//    if (self = [super initWithFrame:frame]) {
//        [self initdata];
//        [self initView];
//    }
//    return self;
//}
zhu's avatar
zhu committed
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
//#pragma mark -获取场景筛选数据
//- (void)getdatasAction
//{
//    
//    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/getSceneFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
//        
//        if ([returnValue[@"code"] isEqualToNumber:@0]) {
//            
//            self.filter = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
//            
//        }
//        else
//        {
//            [self ErrorMBProgressView:returnValue[@"message"]];
//        }
//        
//    } WithErrorCodeBlock:^(id errorCodeValue) {
//        
//    } WithFailureBlock:^(id error) {
//        
//    }];
//}
//
//
//#pragma mark -获取场景列表数据
//- (void)getSceneLibrarydatas:(SceneCondition *)condition
//{
//    [self CreateMBProgressHUDLoding];
//    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
//        
//        
//        [self RemoveMBProgressHUDLoding];
//        if ([returnValue[@"code"] isEqualToNumber:@0]) {
//            
//            self.response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
//            [self.seceneLibararyCollectionView reloadData];
//        }
//        else
//        {
//            [self ErrorMBProgressView:returnValue[@"message"]];
//        }
//        
//    } WithErrorCodeBlock:^(id errorCodeValue) {
//        
//    } WithFailureBlock:^(id error) {
//        
//        [self RemoveMBProgressHUDLoding];
//    }];
//}

zhu's avatar
zhu committed
79
-(void)initdata
zhu's avatar
zhu committed
80
{
zhu's avatar
zhu committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    self.arrayData=[[NSMutableArray alloc]init];
    self.array1=[[NSMutableArray alloc]initWithObjects:@"玄关",@"客厅",@"餐厅",@"主卧室",@"次卧室", @"书房",@"儿童房",@"过厅",@"过道",@"厨房",@"卫生间",@"休闲空间",nil];
     self.array2=[[NSMutableArray alloc]initWithObjects:@"现代简约",@"欧式古典",@"新古典",@"中式",@"新中式", @"混搭",@"小美式风格",@"古典美式风格",@"地中海",@"东南亚",@"日式",@"法式",nil];
     self.array3=[[NSMutableArray alloc]initWithObjects:@"田园",@"宫廷",@"乡村",@"日式风格",@"欧式风格", @"混搭风格",@"现代简约",nil];
    self.arrayData=self.array1;
}
-(void)initView
{

//    空间
    self.kongJianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.kongJianBtn.frame=CGRectMake(ScreenWidth-250, 52, 100, 46) ;
    self.kongJianBtn.backgroundColor=[UIColor whiteColor];
    [self.kongJianBtn setTitle:@"空间   " forState:UIControlStateNormal];
    [self.kongJianBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  self.kongJianBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.kongJianBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.kongJianBtn.tag=101;
    self.kongJianBtn.layer.masksToBounds = YES;
    self.kongJianBtn.layer.cornerRadius = 15;
zhu's avatar
zhu committed
101
    [self.view addSubview:self.kongJianBtn];
zhu's avatar
zhu committed
102 103 104 105 106 107
//    风格
    self.fengGeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.fengGeBtn.frame=CGRectMake(ScreenWidth-250, 102, 100, 46) ;
     self.fengGeBtn.backgroundColor=[UIColor whiteColor];
    [self.fengGeBtn setTitle:@"风格  " forState:UIControlStateNormal];
    [self.fengGeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
zhu's avatar
zhu committed
108

zhu's avatar
zhu committed
109 110 111 112 113
    self.fengGeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.fengGeBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.fengGeBtn.tag=102;
    self.fengGeBtn.layer.masksToBounds = YES;
    self.fengGeBtn.layer.cornerRadius = 15;
zhu's avatar
zhu committed
114
    [self.view addSubview:self.fengGeBtn];
zhu's avatar
zhu committed
115 116 117 118 119 120 121 122 123 124 125
//类型
    self.leiXingBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.leiXingBtn.frame=CGRectMake(ScreenWidth-250, 152, 100, 46) ;
      self.leiXingBtn.backgroundColor=[UIColor whiteColor];
    [self.leiXingBtn setTitle:@"类型   " forState:UIControlStateNormal];
     [self.leiXingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      self.leiXingBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    [self.leiXingBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.leiXingBtn.tag=103;
    self.leiXingBtn.layer.masksToBounds = YES;
    self.leiXingBtn.layer.cornerRadius = 15;
zhu's avatar
zhu committed
126
    [self.view addSubview:self.leiXingBtn];
zhu's avatar
zhu committed
127 128 129
    
   self.subView=[[UIView alloc]initWithFrame:CGRectMake(100, 50, ScreenWidth-300, ScreenHeight-200)];
    self.subView.backgroundColor=[UIColor whiteColor];
zhu's avatar
zhu committed
130
    [self.view  addSubview:self.subView];
zhu's avatar
zhu committed
131
    
zhu's avatar
zhu committed
132
   
zhu's avatar
zhu committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView:)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [[UIApplication sharedApplication].keyWindow addGestureRecognizer:tap];
    [self initSubViews];
}
-(void)initSubViews
{
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.subView.frame.size.width-100, 50)];
    self.headerView.backgroundColor=[UIColor grayColor];
    [self.subView addSubview:self.headerView];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 10, 30, 30);
    [btn setBackgroundImage:[UIImage imageNamed:@"changjingtubiao"] forState:UIControlStateNormal];
    [self.headerView addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(45, 10, 100, 30)];
    lable.text=@"选择场景";
zhu's avatar
zhu committed
151
    [self.headerView addSubview:lable];
zhu's avatar
zhu committed
152 153 154 155
    self.seceneTableView=[[UITableView alloc]initWithFrame:CGRectMake( self.headerView.frame.size.width, 0, 100, self.subView.frame.size.height)];
    self.seceneTableView.delegate=self;
    self.seceneTableView.dataSource=self;
    [self.subView addSubview:self.seceneTableView];
zhu's avatar
zhu committed
156 157 158
    //确定是水平滚动,还是垂直滚动
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
zhu's avatar
zhu committed
159
    
zhu's avatar
zhu committed
160 161 162 163 164 165 166 167 168 169
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake( 0, 50, self.headerView.frame.size.width, self.subView.frame.size.height-50) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    [self.collectionView setBackgroundColor:[UIColor clearColor]];
    
    //注册Cell,必须要有
    [self.collectionView registerClass:[SeceneCollectionPictureCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    
    [self.subView addSubview:self.collectionView];

zhu's avatar
zhu committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
}
-(void)selectedType:(UIButton *)sender
{
    switch (sender.tag) {
        case 101:
//            空间
            self.arrayData=self.array1;
            break;
        case 102:
//            风格
             self.arrayData=self.array2;
            break;
        case 103:
//            类型
             self.arrayData=self.array3;
            break;
        default:
            break;
    }
    [self.seceneTableView reloadData];
}
zhu's avatar
zhu committed
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
#pragma mark -- UICollectionViewDataSource
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 10;
}
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    SeceneCollectionPictureCell * cell = (SeceneCollectionPictureCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
   
    return cell;
}
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(190, 130);
}

//定义每个UICollectionView 的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 0, 20);
}
//定义每个UICollectionView 的纵向间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 2;
}

#pragma mark --UICollectionViewDelegate

//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneCollectionPictureCell * cell = (SeceneCollectionPictureCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if ([self.delegate respondsToSelector:@selector(addSeceneImage:)]) {
        
        [self.delegate addSeceneImage:cell.imageView.image];
    }
}

//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
zhu's avatar
zhu committed
246 247 248 249 250
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
zhu's avatar
zhu committed
251
{
zhu's avatar
zhu committed
252
          return self.arrayData.count;
zhu's avatar
zhu committed
253
     
zhu's avatar
zhu committed
254 255 256
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
257
    
zhu's avatar
zhu committed
258
        return 50;
zhu's avatar
zhu committed
259 260
    
}
zhu's avatar
zhu committed
261 262
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
263
           static NSString *cellID = @"ChooseTansferCell";
zhu's avatar
zhu committed
264 265 266 267 268 269 270 271 272
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            //        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        cell.textLabel.text=[self.arrayData objectAtIndex:indexPath.row];
        
        return cell;
zhu's avatar
zhu committed
273
    
zhu's avatar
zhu committed
274 275 276 277 278 279 280 281 282 283
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}



-(void)DismissScreenView:(UITapGestureRecognizer*)sender{
zhu's avatar
zhu committed
284
    CGPoint point = [sender locationInView:self.view];
zhu's avatar
zhu committed
285 286 287
    if (point.x<100 || point.x >ScreenWidth-100||point.y<50||point.y>ScreenHeight-150) {
        
        if (self) {
zhu's avatar
zhu committed
288
            [self.view removeFromSuperview];
zhu's avatar
zhu committed
289 290 291 292
        }
    }
}

zhu's avatar
zhu committed
293 294 295 296 297 298 299 300 301
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end