FullScreenViewController.m 6.66 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//
//  FullScreenViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/20.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "FullScreenViewController.h"
#import "FullScreenViewCell.h"
#import "ExperienceCentreViewController.h"

@interface FullScreenViewController ()


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

/**
 *  返回按钮
 */
@property (nonatomic,strong) UIButton *backButton;


@end

@implementation FullScreenViewController

static NSString * const reuseIdentifier = @"Cell";

33

曹云霄's avatar
曹云霄 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#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;
    return [super initWithCollectionViewLayout:layout];
}

50

曹云霄's avatar
曹云霄 committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
    [self CreateBackView];
}

#pragma amrk 返回View
- (void)CreateBackView
{
    //产品列表调用
    if (self.isProductLibrary) {
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.backButton.frame = CGRectMake(30, 10, 100, 64);
        [self.backButton setImage:TCImage(@"2-副本") forState:UIControlStateNormal];
66
        [self.backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
67 68 69 70 71 72 73 74 75 76 77
        [self.view addSubview:self.backButton];
        
    }else//场景列表调用
    {
        self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
        self.backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        [self.view addSubview:self.backView];
        //返回按钮
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(30, 0, 100, 64);
        [backButton setImage:TCImage(@"quanping") forState:UIControlStateNormal];
78
        [backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
79 80 81 82 83 84 85 86 87 88
        [self.backView addSubview:backButton];
        
        //体验中心
        UIButton *tiYanCenterButton = [UIButton buttonWithType:UIButtonTypeCustom];
        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];
89
        [tiYanCenterButton addTarget:self action:@selector(gotoTiYanCenterButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
90 91
        [self.backView addSubview:tiYanCenterButton];
    }
92
    [self.collectionView setContentOffset:CGPointMake(ScreenWidth*self.currentIndex, 0)];
曹云霄's avatar
曹云霄 committed
93 94 95
}

#pragma mark -返回
96
- (void)backButtonClick
曹云霄's avatar
曹云霄 committed
97 98 99 100 101
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -体验中心
102
- (void)gotoTiYanCenterButtonClick
曹云霄's avatar
曹云霄 committed
103
{
104
    ExperienceCentreViewController *ExperienceCenter = [ExperienceCentreViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
曹云霄's avatar
曹云霄 committed
105
    TOSceneEntity *sceneModel = [self.datasArray objectAtIndex_opple:self.currentIndex];
106
    SceneListModel *model = [[SceneListModel alloc] initWithDictionary:[sceneModel toDictionary] error:nil];
曹云霄's avatar
曹云霄 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    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;
}

#pragma mark -UI
- (void)uiConfigAction
{
    self.collectionView.pagingEnabled = YES;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[FullScreenViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.datasArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    FullScreenViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.backgroundColor = RGB(251, 248, 241,1);
    if (self.isProductLibrary) {
曹云霄's avatar
曹云霄 committed
144
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[self.datasArray objectAtIndex_opple:indexPath.item]] placeholderImage:REPLACEIMAGE];
曹云霄's avatar
曹云霄 committed
145 146
        return cell;
    }
曹云霄's avatar
曹云霄 committed
147
    TOSceneEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
曹云霄's avatar
曹云霄 committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.pricure] placeholderImage:REPLACEIMAGE];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    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;
            }];
            
        }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;
            }];
        }
170
    }else{
曹云霄's avatar
曹云霄 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
        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;
            }];
        }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;
            }];
        }
    }
}


@end