//
// ODCircleLeftController.m
// oudaBuyer
//
// Created by lixiang on 16/1/18.
// Copyright © 2016年 ouda. All rights reserved.
//
#import “ODCircleLeftController.h”
#import “ODCircleModel.h”
@interface ODCircleLeftController ()
@property (nonatomic, strong) NSMutableArray *arr;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, assign) long selectedTag;
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UIImageView *blurImageView;
@property (nonatomic, strong) UIImageView *designerView;
@property (nonatomic, assign) float moveLength;
@end
@implementation ODCircleLeftController
– (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidthOfScreen, kWidthOfScreen*0.884)];
self.topView = topView;
topView.backgroundColor = [UIColor blackColor];
[self.view addSubview:topView];
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidthOfScreen, kWidthOfScreen*0.884)];
self.imgView = imgView;
[self.topView addSubview:imgView];
self.topView.hidden = YES;
UIImageView *designerView = [[UIImageView alloc]initWithFrame:CGRectMake(0, kWidthOfScreen*0.884, kWidthOfScreen, kWidthOfScreen*0.762)];
designerView.image = [UIImage imageNamed:@”下半部分“];
self.designerView = designerView;
[self.view addSubview:designerView];
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(15, 15, 33, 33)];
[backButton setImage:[UIImage imageNamed:@”返回“] forState:UIControlStateNormal];
[self.view addSubview:backButton];
self.backButton = backButton;
[backButton addTarget:self action:@selector(click2list) forControlEvents:UIControlEventTouchUpInside];
[self requestData];
[self cover];
}
– (NSMutableArray *)arr {
if (_arr == nil) {
self.arr = [NSMutableArray array];
}
return _arr;
}
– (void)requestData {
ODCircleModel *model1 = [ODCircleModel new];
UIImage *image1 = [UIImage imageNamed:@”testImg1″];
model1.image = image1;
[self.arr addObject:model1];
ODCircleModel *model2 = [ODCircleModel new];
UIImage *image2 = [UIImage imageNamed:@”testImg2″];
model2.image = image2;
[self.arr addObject:model2];
ODCircleModel *model3 = [ODCircleModel new];
UIImage *image3 = [UIImage imageNamed:@”testImg3″];
model3.image = image3;
[self.arr addObject:model3];
ODCircleModel *model4 = [ODCircleModel new];
UIImage *image4 = [UIImage imageNamed:@”testImg4″];
model4.image = image4;
[self.arr addObject:model4];
}
/**
* 遮盖层
*/
– (void)cover {
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidthOfScreen, kHeightOfScreen)];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:scrollView];
self.scrollView = scrollView;
for (int i = 0; i < self.arr.count; i++) {
UIButton *button = [UIButton new];
button.tag = i;
[button addTarget:self action:@selector(click2Detail:) forControlEvents:UIControlEventTouchUpInside];
ODCircleModel *model = self.arr[i];
[button setImage:model.image forState:UIControlStateNormal];
[button setBackgroundImage:[model.image blurBlackImage] forState:UIControlStateNormal];
button.imageView.contentMode = UIViewContentModeScaleAspectFill;
button.frame = CGRectMake(0, (i)*kWidthOfScreen*0.625, kWidthOfScreen, kWidthOfScreen*0.884);
[self.scrollView addSubview:button];
}
self.scrollView.contentSize = CGSizeMake(kWidthOfScreen, kWidthOfScreen*0.625*self.arr.count+110);
}
/**
* 点击进入“详情页”
*/
– (void)click2Detail:(UIButton *)sender {
ODCircleModel *model = self.arr[sender.tag];
self.imgView.image = [model.image blurBlackImage];
[self.delegate hideNavBar:YES];
self.selectedTag = sender.tag;
self.scrollView.backgroundColor = [UIColor clearColor];
for (UIButton *btn in self.scrollView.subviews) {
if ([btn isKindOfClass:[UIButton class]]) {
if (btn.tag == sender.tag) {
ODCircleModel *model = self.arr[btn.tag];
UIImageView *blurImageView = [[UIImageView alloc]initWithFrame:btn.frame];
blurImageView.image = [model.image blurBlackImage];
[self.scrollView addSubview:blurImageView];
blurImageView.alpha = 0;
self.blurImageView = blurImageView;
CGPoint point = [btn convertPoint:btn.bounds.origin toView:self.view];
self.designerView.x = btn.x;
self.designerView.y = btn.y;
[UIView animateWithDuration:0.6 animations:^{
btn.transform = CGAffineTransformMakeTranslation(0, -point.y);
self.designerView.frame = CGRectMake(0, kWidthOfScreen*0.884, kWidthOfScreen, kWidthOfScreen*0.762);
self.blurImageView.transform = CGAffineTransformMakeTranslation(0, -point.y);
self.moveLength = point.y;
self.blurImageView.alpha = 1;
}];
}else if(btn.tag>sender.tag){
[UIView animateWithDuration:0.6 animations:^{
CGPoint point = [btn convertPoint:btn.bounds.origin toView:self.view];
btn.transform = CGAffineTransformMakeTranslation(0,kHeightOfScreen – point.y);
}];
}else if (btn.tag<sender.tag){
CGPoint point = [btn convertPoint:btn.bounds.origin toView:self.view];
[UIView animateWithDuration:0.6 animations:^{
btn.transform = CGAffineTransformMakeTranslation(0, -point.y-(sender.tag-btn.tag)*kWidthOfScreen*0.625);
}];
}
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.topView.hidden = NO;
self.scrollView.hidden = YES;
});
}
/**
* 点击回到“列表页”
*/
– (void)click2list {
[self.delegate hideNavBar:NO];
self.scrollView.hidden = NO;
for (UIButton *btn in self.scrollView.subviews) {
if ([btn isKindOfClass:[UIButton class]]) {
if (btn.tag == self.selectedTag) {
[UIView animateWithDuration:0.6 animations:^{
btn.transform = CGAffineTransformMakeTranslation(0,0);
self.blurImageView.transform = CGAffineTransformMakeTranslation(0,0);
self.blurImageView.alpha = 0;
self.designerView.y -= kHeightOfScreen–self.moveLength–self.designerView.y;
}];
}else if(btn.tag > self.selectedTag){
[UIView animateWithDuration:0.6 animations:^{
CGPoint point = [btn convertPoint:btn.bounds.origin toView:self.view];
btn.transform = CGAffineTransformMakeTranslation(0,-(kHeightOfScreen – point.y));
}];
}else if (btn.tag < self.selectedTag){
CGPoint point = [btn convertPoint:btn.bounds.origin toView:self.view];
[UIView animateWithDuration:0.6 animations:^{
btn.transform = CGAffineTransformMakeTranslation(0,point.y+(self.selectedTag-btn.tag)*kWidthOfScreen*0.625);
}];
}
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.scrollView.backgroundColor = [UIColor whiteColor];
});
}
@end