Skip to content

Commit 5c95918

Browse files
author
XcodeYang
committed
update pod 0.1.1 change the way of store the views’ layer in screen by NSHashTable but not NSMutableArray
1 parent 0195eb7 commit 5c95918

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Demo/Pods/XYDebugView/XYDebugView/XYDebug+runtime.m

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

XYDebugView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ s.summary = 'The tool of UIView to Debug its frame'
44
s.description = <<-DESC
55
XYDebugView is debug tool to draw the all views frame in device screen and show it by 2d/3d style like reveal did.
66
DESC
7-
s.version = '0.1.0'
7+
s.version = '0.1.1'
88
s.homepage = "https://github.com/ZhipingYang/XYDebugView"
99
s.license = 'MIT'
1010
s.authors = { 'ZhipingYang' => 'XcodeYang@gmail.com' }

XYDebugView/XYDebug+runtime.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (XYDebugCloneView *)cloneView
6161

6262
- (void)setHasStoreDebugColor:(BOOL)hasStoreDebugColor
6363
{
64-
objc_setAssociatedObject(self, DebugHasStoreUIViewBackColor, @(hasStoreDebugColor), OBJC_ASSOCIATION_ASSIGN);
64+
objc_setAssociatedObject(self, DebugHasStoreUIViewBackColor, @(hasStoreDebugColor), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
6565
}
6666

6767
- (BOOL)hasStoreDebugColor
@@ -98,7 +98,7 @@ - (CGFloat)debug_zPostion
9898

9999
- (void)setDebug_zPostion:(CGFloat)debug_zPostion
100100
{
101-
objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_ASSIGN);
101+
objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
102102
}
103103

104104
- (void)zPositionAnimationFrom:(float)from to:(float)to duration:(NSTimeInterval)duration

XYDebugView/XYDebugWindow.m

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ @interface XYDebugWindow ()
2626

2727
@property (nonatomic, strong) UIScrollView *scrollView;
2828

29-
@property (nonatomic, strong) NSMutableArray <CALayer *>* debugLayers;
29+
@property (nonatomic, strong) NSHashTable <CALayer *> *debugLayers;
3030

3131
@end
3232

@@ -84,7 +84,7 @@ - (instancetype)initWithFrame:(CGRect)frame
8484
[self addSubview:_layerSlider];
8585
[self addSubview:_distanceSlider];
8686
self.backgroundColor = [UIColor clearColor];
87-
self.debugLayers = @[].mutableCopy;
87+
self.debugLayers = [NSHashTable weakObjectsHashTable];
8888
self.layer.masksToBounds = YES;
8989
}
9090
return self;
@@ -116,17 +116,19 @@ - (void)setSouceView:(UIView *)souceView
116116
_souceView = souceView;
117117

118118
if (_souceView == nil) {
119-
[[_debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
120119
_scrollView.hidden = YES;
121120
_layerSlider.hidden = YES;
122121
_distanceSlider.hidden = YES;
123122

124123
} else {
124+
[[self.debugLayers allObjects] makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
125+
[self.debugLayers removeAllObjects];
125126
[self scrollViewAddLayersInView:_souceView layerLevel:0 index:0];
126127
_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0);
127128
_scrollView.hidden = NO;
128129
_layerSlider.hidden = NO;
129130
_distanceSlider.hidden = NO;
131+
[self reCalculateZPostion];
130132
[self recoverLayersDistance];
131133
}
132134
}
@@ -139,7 +141,7 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel
139141
if (view.superview) {
140142
UIView *cloneView = view.cloneView;
141143
cloneView.layer.zPosition = 0;
142-
cloneView.layer.debug_zPostion = (layerLevel*80 + index*8) - 600;
144+
cloneView.layer.debug_zPostion = layerLevel*20+index;
143145
cloneView.layer.masksToBounds = YES;
144146

145147
CGRect frame = [view.superview convertRect:view.frame toView:_souceView];
@@ -159,7 +161,7 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel
159161

160162
- (void)showDifferentLayers:(float)percent
161163
{
162-
CGFloat positionMax = self.debugLayers.firstObject.debug_zPostion;
164+
CGFloat positionMax = self.debugLayers.anyObject.debug_zPostion;
163165
CGFloat positionMin = positionMax;
164166
for (CALayer *layer in self.debugLayers) {
165167
if (layer.debug_zPostion >= positionMax) {
@@ -199,6 +201,27 @@ - (void)changeDistance:(float)percent
199201
}
200202
}
201203

204+
- (void)reCalculateZPostion
205+
{
206+
CGFloat positionMax = self.debugLayers.anyObject.debug_zPostion;
207+
CGFloat positionMin = positionMax;
208+
for (CALayer *layer in self.debugLayers) {
209+
if (layer.debug_zPostion >= positionMax) {
210+
positionMax = layer.debug_zPostion;
211+
}
212+
if (layer.debug_zPostion <= positionMin) {
213+
positionMin = layer.debug_zPostion;
214+
}
215+
}
216+
217+
CGFloat defalutMin = -600;
218+
CGFloat defalutMax = 400;
219+
CGFloat scale = (defalutMax-defalutMin)/(positionMax-positionMin);
220+
for (CALayer *layer in self.debugLayers) {
221+
layer.debug_zPostion = defalutMin + (layer.debug_zPostion - positionMin)*scale;
222+
}
223+
}
224+
202225
- (void)recoverLayersDistance
203226
{
204227
_distanceSlider.defalutPercent = 0.5;

0 commit comments

Comments
 (0)