forked from Tencent/QMUI_iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CALayer+QMUI.m
131 lines (117 loc) · 7.91 KB
/
CALayer+QMUI.m
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// CALayer+QMUI.m
// qmui
//
// Created by MoLice on 16/8/12.
// Copyright © 2016年 QMUI Team. All rights reserved.
//
#import "CALayer+QMUI.h"
#import "QMUICore.h"
@implementation CALayer (QMUI)
- (void)qmui_sendSublayerToBack:(CALayer *)sublayer {
if (sublayer.superlayer == self) {
[sublayer removeFromSuperlayer];
[self insertSublayer:sublayer atIndex:0];
}
}
- (void)qmui_bringSublayerToFront:(CALayer *)sublayer {
if (sublayer.superlayer == self) {
[sublayer removeFromSuperlayer];
[self insertSublayer:sublayer atIndex:(unsigned)self.sublayers.count];
}
}
- (void)qmui_removeDefaultAnimations {
NSMutableDictionary<NSString *, id<CAAction>> *actions = @{NSStringFromSelector(@selector(bounds)): [NSNull null],
NSStringFromSelector(@selector(position)): [NSNull null],
NSStringFromSelector(@selector(zPosition)): [NSNull null],
NSStringFromSelector(@selector(anchorPoint)): [NSNull null],
NSStringFromSelector(@selector(anchorPointZ)): [NSNull null],
NSStringFromSelector(@selector(transform)): [NSNull null],
BeginIgnoreClangWarning(-Wundeclared-selector)
NSStringFromSelector(@selector(hidden)): [NSNull null],
NSStringFromSelector(@selector(doubleSided)): [NSNull null],
EndIgnoreClangWarning
NSStringFromSelector(@selector(sublayerTransform)): [NSNull null],
NSStringFromSelector(@selector(masksToBounds)): [NSNull null],
NSStringFromSelector(@selector(contents)): [NSNull null],
NSStringFromSelector(@selector(contentsRect)): [NSNull null],
NSStringFromSelector(@selector(contentsScale)): [NSNull null],
NSStringFromSelector(@selector(contentsCenter)): [NSNull null],
NSStringFromSelector(@selector(minificationFilterBias)): [NSNull null],
NSStringFromSelector(@selector(backgroundColor)): [NSNull null],
NSStringFromSelector(@selector(cornerRadius)): [NSNull null],
NSStringFromSelector(@selector(borderWidth)): [NSNull null],
NSStringFromSelector(@selector(borderColor)): [NSNull null],
NSStringFromSelector(@selector(opacity)): [NSNull null],
NSStringFromSelector(@selector(compositingFilter)): [NSNull null],
NSStringFromSelector(@selector(filters)): [NSNull null],
NSStringFromSelector(@selector(backgroundFilters)): [NSNull null],
NSStringFromSelector(@selector(shouldRasterize)): [NSNull null],
NSStringFromSelector(@selector(rasterizationScale)): [NSNull null],
NSStringFromSelector(@selector(shadowColor)): [NSNull null],
NSStringFromSelector(@selector(shadowOpacity)): [NSNull null],
NSStringFromSelector(@selector(shadowOffset)): [NSNull null],
NSStringFromSelector(@selector(shadowRadius)): [NSNull null],
NSStringFromSelector(@selector(shadowPath)): [NSNull null]}.mutableCopy;
if ([self isKindOfClass:[CAShapeLayer class]]) {
[actions addEntriesFromDictionary:@{NSStringFromSelector(@selector(path)): [NSNull null],
NSStringFromSelector(@selector(fillColor)): [NSNull null],
NSStringFromSelector(@selector(strokeColor)): [NSNull null],
NSStringFromSelector(@selector(strokeStart)): [NSNull null],
NSStringFromSelector(@selector(strokeEnd)): [NSNull null],
NSStringFromSelector(@selector(lineWidth)): [NSNull null],
NSStringFromSelector(@selector(miterLimit)): [NSNull null],
NSStringFromSelector(@selector(lineDashPhase)): [NSNull null]}];
}
if ([self isKindOfClass:[CAGradientLayer class]]) {
[actions addEntriesFromDictionary:@{NSStringFromSelector(@selector(colors)): [NSNull null],
NSStringFromSelector(@selector(locations)): [NSNull null],
NSStringFromSelector(@selector(startPoint)): [NSNull null],
NSStringFromSelector(@selector(endPoint)): [NSNull null]}];
}
self.actions = actions;
}
+ (CAShapeLayer *)qmui_seperatorDashLayerWithLineLength:(NSInteger)lineLength
lineSpacing:(NSInteger)lineSpacing
lineWidth:(CGFloat)lineWidth
lineColor:(CGColorRef)lineColor
isHorizontal:(BOOL)isHorizontal {
CAShapeLayer *layer = [CAShapeLayer layer];
layer.fillColor = UIColorClear.CGColor;
layer.strokeColor = lineColor;
layer.lineWidth = lineWidth;
layer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInteger:lineLength], [NSNumber numberWithInteger:lineSpacing], nil];
layer.masksToBounds = YES;
CGMutablePathRef path = CGPathCreateMutable();
if (isHorizontal) {
CGPathMoveToPoint(path, NULL, 0, lineWidth / 2);
CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, lineWidth / 2);
} else {
CGPathMoveToPoint(path, NULL, lineWidth / 2, 0);
CGPathAddLineToPoint(path, NULL, lineWidth / 2, SCREEN_HEIGHT);
}
layer.path = path;
CGPathRelease(path);
return layer;
}
+ (CAShapeLayer *)qmui_seperatorDashLayerInHorizontal {
CAShapeLayer *layer = [CAShapeLayer qmui_seperatorDashLayerWithLineLength:2 lineSpacing:2 lineWidth:PixelOne lineColor:UIColorSeparatorDashed.CGColor isHorizontal:YES];
return layer;
}
+ (CAShapeLayer *)qmui_seperatorDashLayerInVertical {
CAShapeLayer *layer = [CAShapeLayer qmui_seperatorDashLayerWithLineLength:2 lineSpacing:2 lineWidth:PixelOne lineColor:UIColorSeparatorDashed.CGColor isHorizontal:NO];
return layer;
}
+ (CALayer *)qmui_separatorLayer {
CALayer *layer = [CALayer layer];
[layer qmui_removeDefaultAnimations];
layer.backgroundColor = UIColorSeparator.CGColor;
layer.frame = CGRectMake(0, 0, 0, PixelOne);
return layer;
}
+ (CALayer *)qmui_separatorLayerForTableView {
CALayer *layer = [self qmui_separatorLayer];
layer.backgroundColor = TableViewSeparatorColor.CGColor;
return layer;
}
@end