Skip to content

Commit

Permalink
update pod 0.1.1 change the way of store the views’ layer in screen b…
Browse files Browse the repository at this point in the history
…y NSHashTable but not NSMutableArray
  • Loading branch information
XcodeYang committed May 31, 2017
1 parent 0195eb7 commit 5c95918
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Demo/Pods/XYDebugView/XYDebugView/XYDebug+runtime.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion XYDebugView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ s.summary = 'The tool of UIView to Debug its frame'
s.description = <<-DESC
XYDebugView is debug tool to draw the all views frame in device screen and show it by 2d/3d style like reveal did.
DESC
s.version = '0.1.0'
s.version = '0.1.1'
s.homepage = "https://github.com/ZhipingYang/XYDebugView"
s.license = 'MIT'
s.authors = { 'ZhipingYang' => 'XcodeYang@gmail.com' }
Expand Down
4 changes: 2 additions & 2 deletions XYDebugView/XYDebug+runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (XYDebugCloneView *)cloneView

- (void)setHasStoreDebugColor:(BOOL)hasStoreDebugColor
{
objc_setAssociatedObject(self, DebugHasStoreUIViewBackColor, @(hasStoreDebugColor), OBJC_ASSOCIATION_ASSIGN);
objc_setAssociatedObject(self, DebugHasStoreUIViewBackColor, @(hasStoreDebugColor), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)hasStoreDebugColor
Expand Down Expand Up @@ -98,7 +98,7 @@ - (CGFloat)debug_zPostion

- (void)setDebug_zPostion:(CGFloat)debug_zPostion
{
objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_ASSIGN);
objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)zPositionAnimationFrom:(float)from to:(float)to duration:(NSTimeInterval)duration
Expand Down
33 changes: 28 additions & 5 deletions XYDebugView/XYDebugWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface XYDebugWindow ()

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) NSMutableArray <CALayer *>* debugLayers;
@property (nonatomic, strong) NSHashTable <CALayer *> *debugLayers;

@end

Expand Down Expand Up @@ -84,7 +84,7 @@ - (instancetype)initWithFrame:(CGRect)frame
[self addSubview:_layerSlider];
[self addSubview:_distanceSlider];
self.backgroundColor = [UIColor clearColor];
self.debugLayers = @[].mutableCopy;
self.debugLayers = [NSHashTable weakObjectsHashTable];
self.layer.masksToBounds = YES;
}
return self;
Expand Down Expand Up @@ -116,17 +116,19 @@ - (void)setSouceView:(UIView *)souceView
_souceView = souceView;

if (_souceView == nil) {
[[_debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
_scrollView.hidden = YES;
_layerSlider.hidden = YES;
_distanceSlider.hidden = YES;

} else {
[[self.debugLayers allObjects] makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
[self.debugLayers removeAllObjects];
[self scrollViewAddLayersInView:_souceView layerLevel:0 index:0];
_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0);
_scrollView.hidden = NO;
_layerSlider.hidden = NO;
_distanceSlider.hidden = NO;
[self reCalculateZPostion];
[self recoverLayersDistance];
}
}
Expand All @@ -139,7 +141,7 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel
if (view.superview) {
UIView *cloneView = view.cloneView;
cloneView.layer.zPosition = 0;
cloneView.layer.debug_zPostion = (layerLevel*80 + index*8) - 600;
cloneView.layer.debug_zPostion = layerLevel*20+index;
cloneView.layer.masksToBounds = YES;

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

- (void)showDifferentLayers:(float)percent
{
CGFloat positionMax = self.debugLayers.firstObject.debug_zPostion;
CGFloat positionMax = self.debugLayers.anyObject.debug_zPostion;
CGFloat positionMin = positionMax;
for (CALayer *layer in self.debugLayers) {
if (layer.debug_zPostion >= positionMax) {
Expand Down Expand Up @@ -199,6 +201,27 @@ - (void)changeDistance:(float)percent
}
}

- (void)reCalculateZPostion
{
CGFloat positionMax = self.debugLayers.anyObject.debug_zPostion;
CGFloat positionMin = positionMax;
for (CALayer *layer in self.debugLayers) {
if (layer.debug_zPostion >= positionMax) {
positionMax = layer.debug_zPostion;
}
if (layer.debug_zPostion <= positionMin) {
positionMin = layer.debug_zPostion;
}
}

CGFloat defalutMin = -600;
CGFloat defalutMax = 400;
CGFloat scale = (defalutMax-defalutMin)/(positionMax-positionMin);
for (CALayer *layer in self.debugLayers) {
layer.debug_zPostion = defalutMin + (layer.debug_zPostion - positionMin)*scale;
}
}

- (void)recoverLayersDistance
{
_distanceSlider.defalutPercent = 0.5;
Expand Down

0 comments on commit 5c95918

Please sign in to comment.