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

#import "FullScreenViewController.h"
#import "FullScreenViewCell.h"
11
#import "ExperienceCentreViewController.h"
勾芒's avatar
勾芒 committed
12 13 14 15 16 17 18 19 20

@interface FullScreenViewController ()


/**
 *  返回View
 */
@property (nonatomic,strong) UIView *backView;

勾芒's avatar
勾芒 committed
21 22 23 24 25
/**
 *  返回按钮
 */
@property (nonatomic,strong) UIButton *backButton;

26 27 28 29 30
/**
 *  保存当前下标
 */
@property (nonatomic,assign) NSInteger currentIndex;

勾芒's avatar
勾芒 committed
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
@end

@implementation FullScreenViewController

static NSString * const reuseIdentifier = @"Cell";



#pragma mark -初始化
- (instancetype)init
{
    // 创建一个流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    // 设置cell的尺寸
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    
    // 设置滚动的方向
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    // 行间距
    layout.minimumLineSpacing = 0;
    
    // 设置cell之间的间距
    layout.minimumInteritemSpacing = 0;
    //
    //    // 组间距
    //    layout.sectionInset = UIEdgeInsetsMake(100, 20, 0, 30);
    
    return [super initWithCollectionViewLayout:layout];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
    [self CreateBackView];
}


#pragma amrk 返回View
- (void)CreateBackView
{
勾芒's avatar
勾芒 committed
76
    
勾芒's avatar
勾芒 committed
77
    //产品列表调用
勾芒's avatar
勾芒 committed
78
    if (self.isProductLibrary) {
勾芒's avatar
勾芒 committed
79 80 81 82 83 84 85 86 87 88
        
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.backButton.frame = CGRectMake(30, 10, 100, 64);
        [self.backButton setImage:TCImage(@"2-副本") forState:UIControlStateNormal];
        [self.backButton addTarget:self action:@selector(BackButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.backButton];
        
    }else//场景列表调用
    {
        self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
勾芒's avatar
勾芒 committed
89
        self.backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
勾芒's avatar
勾芒 committed
90 91 92 93 94 95 96 97
        [self.view addSubview:self.backView];
        //返回按钮
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(30, 0, 100, 64);
        [backButton setImage:TCImage(@"quanping") forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(BackButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:backButton];
        
勾芒's avatar
勾芒 committed
98 99
        //体验中心
        UIButton *tiYanCenterButton = [UIButton buttonWithType:UIButtonTypeCustom];
勾芒's avatar
勾芒 committed
100 101 102 103 104 105
        tiYanCenterButton.frame = CGRectMake(ScreenWidth-150, 10, 100, 44);
        tiYanCenterButton.layer.masksToBounds = YES;
        tiYanCenterButton.layer.cornerRadius = kCornerRadius;
        tiYanCenterButton.layer.borderWidth = 1;
        tiYanCenterButton.layer.borderColor = [UIColor whiteColor].CGColor;
        [tiYanCenterButton setTitle:@"体验中心" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
106 107 108
        [tiYanCenterButton addTarget:self action:@selector(GotoTiYanCenterButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:tiYanCenterButton];
    }
勾芒's avatar
勾芒 committed
109
    [self.collectionView setContentOffset:CGPointMake(ScreenWidth*self.currentindex, 0)];
勾芒's avatar
勾芒 committed
110 111 112 113 114 115 116 117
}

#pragma mark -返回
- (void)BackButtonClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

勾芒's avatar
勾芒 committed
118 119 120
#pragma mark -体验中心
- (void)GotoTiYanCenterButtonClick
{
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    ExperienceCentreViewController *ExperienceCenter = [storyboard instantiateViewControllerWithIdentifier:@"ExperienceCentre"];
    TOSceneEntity *sceneModel = [self.datasArray objectAtIndex_opple:self.currentIndex];
    SceneListModel *model = [[SceneListModel alloc]init];
    model.fid = sceneModel.fid;
    model.sceneCode = sceneModel.sceneCode;
    model.name = sceneModel.name;
    model.pricure = sceneModel.pricure;
    model.category = sceneModel.category;
    model.style = sceneModel.style;
    model.space = sceneModel.space;
    model.isSelectedSate = YES;
    [ExperienceCenter.sceneDatasArray addObject:model];
    ExperienceCenter.boolValue = YES;
    ExperienceCenter.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *popover = ExperienceCenter.popoverPresentationController;
    popover.sourceView = ExperienceCenter.view;
    [self presentViewController:ExperienceCenter animated:YES completion:nil];
}

#pragma mark -获取当前下标
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGPoint offset = scrollView.contentOffset;
    int index = offset.x/self.view.frame.size.width;
    self.currentIndex = index;
勾芒's avatar
勾芒 committed
147
}
勾芒's avatar
勾芒 committed
148 149 150 151 152

#pragma mark -UI
- (void)uiConfigAction
{
    self.collectionView.pagingEnabled = YES;
勾芒's avatar
勾芒 committed
153
    self.collectionView.backgroundColor = [UIColor whiteColor];
勾芒's avatar
勾芒 committed
154 155 156 157 158 159 160
    [self.collectionView registerClass:[FullScreenViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
勾芒's avatar
勾芒 committed
161
    return self.datasArray.count;
勾芒's avatar
勾芒 committed
162 163 164 165 166
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    FullScreenViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
167
    cell.backgroundColor = kTCColor(251, 248, 241);
勾芒's avatar
勾芒 committed
168 169 170 171 172 173
    if (self.isProductLibrary) {
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[self.datasArray objectAtIndex_opple:indexPath.item]] placeholderImage:REPLACEIMAGE];
        return cell;
    }
    TOSceneEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.pricure] placeholderImage:REPLACEIMAGE];
勾芒's avatar
勾芒 committed
174 175 176 177 178
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
179 180 181 182 183 184 185 186 187 188 189
    
    if (self.isProductLibrary) {
        if (self.backButton.frame.origin.y == 10) {
            
            [UIView animateWithDuration:0.3 animations:^{
                
                CGRect frame = self.backButton.frame;
                frame.origin.y = -64;
                self.backButton.frame = frame;
                
            }];
勾芒's avatar
勾芒 committed
190
            
勾芒's avatar
勾芒 committed
191 192 193 194 195 196 197 198 199 200 201
        }else if (self.backButton.frame.origin.y == -64)
        {
            [UIView animateWithDuration:0.3 animations:^{
                
                CGRect frame = self.backButton.frame;
                frame.origin.y = 10;
                self.backButton.frame = frame;
            }];
        }
        
    }else
勾芒's avatar
勾芒 committed
202 203
        
    {
勾芒's avatar
勾芒 committed
204 205 206 207 208 209 210 211 212
        if (self.backView.frame.origin.y == 0) {
            
            [UIView animateWithDuration:0.3 animations:^{
                
                CGRect frame = self.backView.frame;
                frame.origin.y = -64;
                self.backView.frame = frame;
                
            }];
勾芒's avatar
勾芒 committed
213
            
勾芒's avatar
勾芒 committed
214 215 216 217 218 219 220 221 222
        }else if (self.backView.frame.origin.y == -64)
        {
            [UIView animateWithDuration:0.3 animations:^{
                
                CGRect frame = self.backView.frame;
                frame.origin.y = 0;
                self.backView.frame = frame;
            }];
        }
勾芒's avatar
勾芒 committed
223
    }
勾芒's avatar
勾芒 committed
224

勾芒's avatar
勾芒 committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

- (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