-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJCFrameMake.m
More file actions
114 lines (92 loc) · 2.78 KB
/
JCFrameMake.m
File metadata and controls
114 lines (92 loc) · 2.78 KB
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// JCLayoutMaker.m
// JCFrameLayout
//
// Created by abc on 17/3/27.
// Copyright © 2017年 jackcat. All rights reserved.
//
#import "JCFrameMake.h"
#import "UIView+JCFrame.h"
#import "JCFrameExecutor.h"
@interface JCFrameMake ()<JCFrameDelegate>
/**
* <#注释#>
**/
@property (nonatomic,weak) UIView *view;
@end
@implementation JCFrameMake
#pragma mark - init
- (instancetype)initWithView:(UIView *)view{
self = [super init];
if (self) {
self.view = view;
}
return self;
}
#pragma mark - support chainable syntax
- (JCFrame *)left{
return [self createJCLayoutFrame:JCFrameTypeLeft];
}
- (JCFrame *)right{
return [self createJCLayoutFrame:JCFrameTypeRight];
}
- (JCFrame *)top{
return [self createJCLayoutFrame:JCFrameTypeTop];
}
- (JCFrame *)bottom{
return [self createJCLayoutFrame:JCFrameTypeBottom];
}
- (JCFrame *)width{
return [self createJCLayoutFrame:JCFrameTypeWidth];
}
- (JCFrame *)height{
return [self createJCLayoutFrame:JCFrameTypeHeight];
}
- (JCFrame *)centerX{
return [self createJCLayoutFrame:JCFrameTypeCenterX];
}
- (JCFrame *)centerY{
return [self createJCLayoutFrame:JCFrameTypeCenterY];
}
- (JCFrame *)center{
return [self createJCLayoutFrame:JCFrameTypeCenter];
}
- (JCFrame*)size{
return [self createJCLayoutFrame:JCFrameTypeSize];
}
#pragma mark - JCFrameDelegate
- (JCFrame*)jcFrame:(JCFrame *)jcFrame createFrameWithframeType:(JCFrameType)frameType{
return [self createJCLayoutFrame:frameType];
}
- (JCFrame *)createJCLayoutFrame:(JCFrameType)frameType{
if (self.view.jc_settedFrameTypes & frameType) {
/**
如果这个frameType已存在,则直接返回,反之创建
*/
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(JCFrame *frame, id obj) {
return frame.frameAttr.currentFrameType == frameType;
}];
NSArray *filterResult = [self.view.jc_frames filteredArrayUsingPredicate:predicate];
return filterResult.firstObject;
}else{
//1.将frameType标记为已存在
self.view.jc_settedFrameTypes |= frameType;
//2.创建JCFrameAttribute
JCFrameAttribute *frameAttribute = [[JCFrameAttribute alloc]initWithView:self.view frameType:frameType];
//3.创建JCFrame
JCFrame *frame = [[JCFrame alloc]initWithFrameAttribute:frameAttribute];
//4.设置JCFrame代理
frame.delegate = self;
//5.将JCFrame添加至UIView的jc_frames集合中
[self.view.jc_frames addObject:frame];
return frame;
}
}
- (void)executeLayout{
[JCFrameExecutor executeWithView:self.view];
JCLog(@"--frames = %@",self.view.jc_frames);
}
- (void)dealloc{
JCLog(@"---JCFrameMake dealloc");
}
@end