diff --git a/Demo/Pods/Pods.xcodeproj/project.pbxproj b/Demo/Pods/Pods.xcodeproj/project.pbxproj index 63b60f2..df9d2af 100644 --- a/Demo/Pods/Pods.xcodeproj/project.pbxproj +++ b/Demo/Pods/Pods.xcodeproj/project.pbxproj @@ -13,8 +13,8 @@ 5681F2EB82C5AE4F2F531ABE76C4FB02 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D88AAE1F92055A60CC2FC970D7D34634 /* Foundation.framework */; }; 65758CD51ED6B75800A7738D /* XYDebugView.h in Headers */ = {isa = PBXBuildFile; fileRef = 65758CC51ED6B16700A7738D /* XYDebugView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 65758CD61ED6B75F00A7738D /* XYDebugView.m in Sources */ = {isa = PBXBuildFile; fileRef = 65758CC61ED6B16700A7738D /* XYDebugView.m */; }; - 65758CD71ED6B76B00A7738D /* UIView+XYDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 65758CC91ED6B1EA00A7738D /* UIView+XYDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 65758CD81ED6B76B00A7738D /* UIView+XYDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 65758CCA1ED6B1EA00A7738D /* UIView+XYDebug.m */; }; + 65758CD71ED6B76B00A7738D /* XYDebug+runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 65758CC91ED6B1EA00A7738D /* XYDebug+runtime.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 65758CD81ED6B76B00A7738D /* XYDebug+runtime.m in Sources */ = {isa = PBXBuildFile; fileRef = 65758CCA1ED6B1EA00A7738D /* XYDebug+runtime.m */; }; 65758CD91ED6B76B00A7738D /* UIColor+XYRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 65758CCD1ED6B36500A7738D /* UIColor+XYRandom.h */; settings = {ATTRIBUTES = (Public, ); }; }; 65758CDA1ED6B76B00A7738D /* UIColor+XYRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 65758CCE1ED6B36500A7738D /* UIColor+XYRandom.m */; }; 65758CDB1ED6B76B00A7738D /* XYDebugWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 65758CD11ED6B49D00A7738D /* XYDebugWindow.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -46,8 +46,8 @@ 4DAD1C7035182AA3EC2731048C0AA9D9 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65758CC51ED6B16700A7738D /* XYDebugView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XYDebugView.h; sourceTree = ""; }; 65758CC61ED6B16700A7738D /* XYDebugView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XYDebugView.m; sourceTree = ""; }; - 65758CC91ED6B1EA00A7738D /* UIView+XYDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+XYDebug.h"; sourceTree = ""; }; - 65758CCA1ED6B1EA00A7738D /* UIView+XYDebug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+XYDebug.m"; sourceTree = ""; }; + 65758CC91ED6B1EA00A7738D /* XYDebug+runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XYDebug+runtime.h"; sourceTree = ""; }; + 65758CCA1ED6B1EA00A7738D /* XYDebug+runtime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XYDebug+runtime.m"; sourceTree = ""; }; 65758CCD1ED6B36500A7738D /* UIColor+XYRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+XYRandom.h"; sourceTree = ""; }; 65758CCE1ED6B36500A7738D /* UIColor+XYRandom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+XYRandom.m"; sourceTree = ""; }; 65758CD11ED6B49D00A7738D /* XYDebugWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XYDebugWindow.h; sourceTree = ""; }; @@ -167,8 +167,8 @@ FD292D03A3747EB1F9BA923B2DE72086 /* XYDebugViewManager.m */, 65758CC51ED6B16700A7738D /* XYDebugView.h */, 65758CC61ED6B16700A7738D /* XYDebugView.m */, - 65758CC91ED6B1EA00A7738D /* UIView+XYDebug.h */, - 65758CCA1ED6B1EA00A7738D /* UIView+XYDebug.m */, + 65758CC91ED6B1EA00A7738D /* XYDebug+runtime.h */, + 65758CCA1ED6B1EA00A7738D /* XYDebug+runtime.m */, 65758CCD1ED6B36500A7738D /* UIColor+XYRandom.h */, 65758CCE1ED6B36500A7738D /* UIColor+XYRandom.m */, 65758CD11ED6B49D00A7738D /* XYDebugWindow.h */, @@ -213,7 +213,7 @@ CB9B5B0878030C8F3B0C8D7AB6F51798 /* XYDebugView-umbrella.h in Headers */, D90865DD8E1D3C2EE659E24B8371FEBA /* XYDebugViewManager.h in Headers */, 65758CDB1ED6B76B00A7738D /* XYDebugWindow.h in Headers */, - 65758CD71ED6B76B00A7738D /* UIView+XYDebug.h in Headers */, + 65758CD71ED6B76B00A7738D /* XYDebug+runtime.h in Headers */, 65758CD51ED6B75800A7738D /* XYDebugView.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -293,7 +293,7 @@ 017D43B065C9D4444CF7B72F9746E6C2 /* XYDebugView-dummy.m in Sources */, 00CADD8508F38C4F931BFD2CF3BB8C7E /* XYDebugViewManager.m in Sources */, 65758CD61ED6B75F00A7738D /* XYDebugView.m in Sources */, - 65758CD81ED6B76B00A7738D /* UIView+XYDebug.m in Sources */, + 65758CD81ED6B76B00A7738D /* XYDebug+runtime.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Demo/Pods/XYDebugView/UIView+XYDebug.h b/Demo/Pods/XYDebugView/XYDebug+runtime.h similarity index 84% rename from Demo/Pods/XYDebugView/UIView+XYDebug.h rename to Demo/Pods/XYDebugView/XYDebug+runtime.h index cc3df65..f4ce933 100644 --- a/Demo/Pods/XYDebugView/UIView+XYDebug.h +++ b/Demo/Pods/XYDebugView/XYDebug+runtime.h @@ -17,3 +17,10 @@ @property (nonatomic, copy, readonly) NSArray *debuRecurrenceAllSubviews; @end + +@interface CALayer (XYDebug) + +@property (nonatomic, assign) CGFloat debug_zPostion; + +@end + diff --git a/Demo/Pods/XYDebugView/UIView+XYDebug.m b/Demo/Pods/XYDebugView/XYDebug+runtime.m similarity index 86% rename from Demo/Pods/XYDebugView/UIView+XYDebug.m rename to Demo/Pods/XYDebugView/XYDebug+runtime.m index 1365cd6..16f4172 100644 --- a/Demo/Pods/XYDebugView/UIView+XYDebug.m +++ b/Demo/Pods/XYDebugView/XYDebug+runtime.m @@ -6,7 +6,7 @@ // // -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #import const static char * DebugStoreUIViewBackColor = "DebugStoreUIViewBackColor"; @@ -84,3 +84,22 @@ - (BOOL)hasStoreDebugColor } @end + + +const static char * DebugStoreZPosition = "DebugStoreZPosition"; + + +@implementation CALayer (XYDebug) + +- (CGFloat)debug_zPostion +{ + id obj = objc_getAssociatedObject(self, DebugStoreZPosition); + return [obj floatValue]; +} + +- (void)setDebug_zPostion:(CGFloat)debug_zPostion +{ + objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_ASSIGN); +} + +@end diff --git a/Demo/Pods/XYDebugView/XYDebugView.m b/Demo/Pods/XYDebugView/XYDebugView.m index 7ccae5b..4d69ec5 100644 --- a/Demo/Pods/XYDebugView/XYDebugView.m +++ b/Demo/Pods/XYDebugView/XYDebugView.m @@ -63,6 +63,7 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _colorLayer = [CALayer layer]; + _colorLayer.frame = CGRectMake(0, 0, frame.size.width, 0); _colorLayer.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.4].CGColor; [self.layer addSublayer:_colorLayer]; } @@ -75,13 +76,13 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event CGPoint point = [touch locationInView:self]; _colorLayer.frame = CGRectMake(0, 0, self.bounds.size.width, point.y); float percent = point.y / self.frame.size.height; - percent = percent<0 ? percent : (percent>1 ? 1:percent); + percent = percent<0 ? 0 : (percent>1 ? 1:percent); !_touchMoveBlock ?: _touchMoveBlock(percent); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - _colorLayer.frame = CGRectZero; + _colorLayer.frame = CGRectMake(0, 0, self.bounds.size.width, 0); !_touchEndBlock ?: _touchEndBlock(); } diff --git a/Demo/Pods/XYDebugView/XYDebugView/XYDebugViewManager.m b/Demo/Pods/XYDebugView/XYDebugView/XYDebugViewManager.m index ad3eb7d..8e02fb0 100644 --- a/Demo/Pods/XYDebugView/XYDebugView/XYDebugViewManager.m +++ b/Demo/Pods/XYDebugView/XYDebugView/XYDebugViewManager.m @@ -8,7 +8,7 @@ #import "XYDebugViewManager.h" #import "XYDebugWindow.h" -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #import "UIColor+XYRandom.h" #pragma mark - XYDebugViewManager diff --git a/Demo/Pods/XYDebugView/XYDebugWindow.h b/Demo/Pods/XYDebugView/XYDebugWindow.h index fc2cb2d..768373a 100644 --- a/Demo/Pods/XYDebugView/XYDebugWindow.h +++ b/Demo/Pods/XYDebugView/XYDebugWindow.h @@ -14,8 +14,5 @@ @property (nonatomic, weak) XYDebugViewManager *frameManager; @property (nonatomic, weak) UIView *souceView; @property (nonatomic, strong) UIButton *button; -@property (nonatomic, strong) DebugSlider *slider; -@property (nonatomic, strong) UIScrollView *scrollView; -@property (nonatomic, strong) NSMutableArray * debugLayers; @end diff --git a/Demo/Pods/XYDebugView/XYDebugWindow.m b/Demo/Pods/XYDebugView/XYDebugWindow.m index d017ed2..6f9ac17 100644 --- a/Demo/Pods/XYDebugView/XYDebugWindow.m +++ b/Demo/Pods/XYDebugView/XYDebugWindow.m @@ -8,7 +8,7 @@ #import "XYDebugWindow.h" #import "XYDebugViewManager.h" -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #ifndef SCREEN_WIDTH #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width @@ -18,6 +18,17 @@ #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height #endif +@interface XYDebugWindow () + +@property (nonatomic, strong) DebugSlider *layerSlider; +@property (nonatomic, strong) DebugSlider *distanceSlider; + +@property (nonatomic, strong) UIScrollView *scrollView; + +@property (nonatomic, strong) NSMutableArray * debugLayers; + +@end + @implementation XYDebugWindow - (instancetype)initWithFrame:(CGRect)frame @@ -43,21 +54,32 @@ - (instancetype)initWithFrame:(CGRect)frame transform.m34 = -1.0 / 500; _scrollView.layer.sublayerTransform = transform; - _slider = [[DebugSlider alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-30, 40, 40, SCREEN_HEIGHT-40*2)]; - _slider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; - _slider.hidden = YES; + _layerSlider = [[DebugSlider alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-30, 40, 30, SCREEN_HEIGHT-40*2)]; + _layerSlider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; + _layerSlider.hidden = YES; + + _distanceSlider = [[DebugSlider alloc] initWithFrame:CGRectMake(0, 40, 30, SCREEN_HEIGHT-40*2)]; + _distanceSlider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; + _distanceSlider.hidden = YES; typeof(self) weakSelf = self; - _slider.touchMoveBlock = ^(float percent) { + _layerSlider.touchMoveBlock = ^(float percent) { [weakSelf showDifferentLayers:percent]; }; - _slider.touchEndBlock = ^{ + _layerSlider.touchEndBlock = ^{ [weakSelf showAllLayer]; }; + _distanceSlider.touchMoveBlock = ^(float percent) { + [weakSelf changeDistance:percent]; + }; + _distanceSlider.touchEndBlock = ^{ + [weakSelf recoverDistance]; + }; [self addSubview:_scrollView]; [self addSubview:_button]; - [self addSubview:_slider]; + [self addSubview:_layerSlider]; + [self addSubview:_distanceSlider]; self.backgroundColor = [UIColor clearColor]; self.debugLayers = @[].mutableCopy; self.layer.masksToBounds = YES; @@ -74,8 +96,10 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event } else if (_frameManager.isDebugging) { if (CGRectContainsPoint(_button.frame,point)) { return _button; - } else if (CGRectContainsPoint(_slider.frame,point) && _souceView) { - return _slider; + } else if (CGRectContainsPoint(_layerSlider.frame,point) && _souceView) { + return _layerSlider; + } else if (CGRectContainsPoint(_distanceSlider.frame,point) && _souceView) { + return _distanceSlider; } else if (CGRectContainsPoint(_scrollView.frame,point) && _souceView) { return _scrollView; } @@ -88,15 +112,21 @@ - (void)setSouceView:(UIView *)souceView { _souceView = souceView; if (_souceView == nil) { - [[self.debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; - self.scrollView.hidden = YES; - self.slider.hidden = YES; + [[_debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; + _scrollView.hidden = YES; + _layerSlider.hidden = YES; + _distanceSlider.hidden = YES; } else { - self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); + _scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); [self scrollViewAddLayersInView:_souceView layerLevel:0 index:0]; - self.scrollView.hidden = NO; - self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); - self.slider.hidden = NO; + _scrollView.hidden = NO; + _scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); + _layerSlider.hidden = NO; + _distanceSlider.hidden = NO; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.debugLayers enumerateObjectsUsingBlock:^(CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + }]; + }); } } @@ -105,7 +135,8 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel if ([view isKindOfClass:[UIView class]] && view) { if (view.superview) { UIView *cloneView = view.cloneView; - cloneView.layer.zPosition = -600 + (layerLevel*80+index*8); + cloneView.layer.zPosition = 0; + cloneView.layer.debug_zPostion = -600 + (layerLevel*80+index*8); cloneView.layer.masksToBounds = YES; CGRect frame = [view.superview convertRect:view.frame toView:_souceView]; @@ -114,25 +145,34 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel cloneView.layer.opacity = 0.8; [self.debugLayers addObject:cloneView.layer]; [self.scrollView.layer addSublayer:cloneView.layer]; + + CABasicAnimation *theAnimation; + theAnimation=[CABasicAnimation animationWithKeyPath:@"zPosition"]; + theAnimation.fromValue=[NSNumber numberWithFloat:0]; + theAnimation.toValue=[NSNumber numberWithFloat:-600 + (layerLevel*80+index*8)]; + theAnimation.duration=1; + theAnimation.fillMode = kCAFillModeForwards; + theAnimation.removedOnCompletion = NO; + [cloneView.layer addAnimation:theAnimation forKey:@"zPosition"]; } - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - [self scrollViewAddLayersInView:obj layerLevel:layerLevel+1 index:idx]; - }]; - }); + [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [self scrollViewAddLayersInView:obj layerLevel:layerLevel+1 index:idx]; + }]; } } +#pragma mark - actions + - (void)showDifferentLayers:(float)percent { - CGFloat positionMax = self.debugLayers.firstObject.zPosition; + CGFloat positionMax = self.debugLayers.firstObject.debug_zPostion; CGFloat positionMin = positionMax; for (CALayer *layer in self.debugLayers) { - if (layer.zPosition >= positionMax) { - positionMax = layer.zPosition; + if (layer.debug_zPostion >= positionMax) { + positionMax = layer.debug_zPostion; } - if (layer.zPosition <= positionMin) { - positionMin = layer.zPosition; + if (layer.debug_zPostion <= positionMin) { + positionMin = layer.debug_zPostion; } } // 分成20节,每节为5 @@ -145,7 +185,7 @@ - (void)showDifferentLayers:(float)percent CGFloat dowmRange = positionMin + gap*(num-1); for (CALayer *layer in self.debugLayers) { - layer.opacity = (layer.zPosition>upRange || layer.zPositionupRange || layer.debug_zPostion 'XcodeYang@gmail.com' } diff --git a/XYDebugView/UIView+XYDebug.h b/XYDebugView/XYDebug+runtime.h similarity index 84% rename from XYDebugView/UIView+XYDebug.h rename to XYDebugView/XYDebug+runtime.h index cc3df65..f4ce933 100644 --- a/XYDebugView/UIView+XYDebug.h +++ b/XYDebugView/XYDebug+runtime.h @@ -17,3 +17,10 @@ @property (nonatomic, copy, readonly) NSArray *debuRecurrenceAllSubviews; @end + +@interface CALayer (XYDebug) + +@property (nonatomic, assign) CGFloat debug_zPostion; + +@end + diff --git a/XYDebugView/UIView+XYDebug.m b/XYDebugView/XYDebug+runtime.m similarity index 86% rename from XYDebugView/UIView+XYDebug.m rename to XYDebugView/XYDebug+runtime.m index 1365cd6..16f4172 100644 --- a/XYDebugView/UIView+XYDebug.m +++ b/XYDebugView/XYDebug+runtime.m @@ -6,7 +6,7 @@ // // -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #import const static char * DebugStoreUIViewBackColor = "DebugStoreUIViewBackColor"; @@ -84,3 +84,22 @@ - (BOOL)hasStoreDebugColor } @end + + +const static char * DebugStoreZPosition = "DebugStoreZPosition"; + + +@implementation CALayer (XYDebug) + +- (CGFloat)debug_zPostion +{ + id obj = objc_getAssociatedObject(self, DebugStoreZPosition); + return [obj floatValue]; +} + +- (void)setDebug_zPostion:(CGFloat)debug_zPostion +{ + objc_setAssociatedObject(self, DebugStoreZPosition, @(debug_zPostion), OBJC_ASSOCIATION_ASSIGN); +} + +@end diff --git a/XYDebugView/XYDebugView.m b/XYDebugView/XYDebugView.m index 7ccae5b..4d69ec5 100644 --- a/XYDebugView/XYDebugView.m +++ b/XYDebugView/XYDebugView.m @@ -63,6 +63,7 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _colorLayer = [CALayer layer]; + _colorLayer.frame = CGRectMake(0, 0, frame.size.width, 0); _colorLayer.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.4].CGColor; [self.layer addSublayer:_colorLayer]; } @@ -75,13 +76,13 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event CGPoint point = [touch locationInView:self]; _colorLayer.frame = CGRectMake(0, 0, self.bounds.size.width, point.y); float percent = point.y / self.frame.size.height; - percent = percent<0 ? percent : (percent>1 ? 1:percent); + percent = percent<0 ? 0 : (percent>1 ? 1:percent); !_touchMoveBlock ?: _touchMoveBlock(percent); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - _colorLayer.frame = CGRectZero; + _colorLayer.frame = CGRectMake(0, 0, self.bounds.size.width, 0); !_touchEndBlock ?: _touchEndBlock(); } diff --git a/XYDebugView/XYDebugViewManager.m b/XYDebugView/XYDebugViewManager.m index ad3eb7d..8e02fb0 100644 --- a/XYDebugView/XYDebugViewManager.m +++ b/XYDebugView/XYDebugViewManager.m @@ -8,7 +8,7 @@ #import "XYDebugViewManager.h" #import "XYDebugWindow.h" -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #import "UIColor+XYRandom.h" #pragma mark - XYDebugViewManager diff --git a/XYDebugView/XYDebugWindow.h b/XYDebugView/XYDebugWindow.h index fc2cb2d..768373a 100644 --- a/XYDebugView/XYDebugWindow.h +++ b/XYDebugView/XYDebugWindow.h @@ -14,8 +14,5 @@ @property (nonatomic, weak) XYDebugViewManager *frameManager; @property (nonatomic, weak) UIView *souceView; @property (nonatomic, strong) UIButton *button; -@property (nonatomic, strong) DebugSlider *slider; -@property (nonatomic, strong) UIScrollView *scrollView; -@property (nonatomic, strong) NSMutableArray * debugLayers; @end diff --git a/XYDebugView/XYDebugWindow.m b/XYDebugView/XYDebugWindow.m index d017ed2..6f9ac17 100644 --- a/XYDebugView/XYDebugWindow.m +++ b/XYDebugView/XYDebugWindow.m @@ -8,7 +8,7 @@ #import "XYDebugWindow.h" #import "XYDebugViewManager.h" -#import "UIView+XYDebug.h" +#import "XYDebug+runtime.h" #ifndef SCREEN_WIDTH #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width @@ -18,6 +18,17 @@ #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height #endif +@interface XYDebugWindow () + +@property (nonatomic, strong) DebugSlider *layerSlider; +@property (nonatomic, strong) DebugSlider *distanceSlider; + +@property (nonatomic, strong) UIScrollView *scrollView; + +@property (nonatomic, strong) NSMutableArray * debugLayers; + +@end + @implementation XYDebugWindow - (instancetype)initWithFrame:(CGRect)frame @@ -43,21 +54,32 @@ - (instancetype)initWithFrame:(CGRect)frame transform.m34 = -1.0 / 500; _scrollView.layer.sublayerTransform = transform; - _slider = [[DebugSlider alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-30, 40, 40, SCREEN_HEIGHT-40*2)]; - _slider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; - _slider.hidden = YES; + _layerSlider = [[DebugSlider alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-30, 40, 30, SCREEN_HEIGHT-40*2)]; + _layerSlider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; + _layerSlider.hidden = YES; + + _distanceSlider = [[DebugSlider alloc] initWithFrame:CGRectMake(0, 40, 30, SCREEN_HEIGHT-40*2)]; + _distanceSlider.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; + _distanceSlider.hidden = YES; typeof(self) weakSelf = self; - _slider.touchMoveBlock = ^(float percent) { + _layerSlider.touchMoveBlock = ^(float percent) { [weakSelf showDifferentLayers:percent]; }; - _slider.touchEndBlock = ^{ + _layerSlider.touchEndBlock = ^{ [weakSelf showAllLayer]; }; + _distanceSlider.touchMoveBlock = ^(float percent) { + [weakSelf changeDistance:percent]; + }; + _distanceSlider.touchEndBlock = ^{ + [weakSelf recoverDistance]; + }; [self addSubview:_scrollView]; [self addSubview:_button]; - [self addSubview:_slider]; + [self addSubview:_layerSlider]; + [self addSubview:_distanceSlider]; self.backgroundColor = [UIColor clearColor]; self.debugLayers = @[].mutableCopy; self.layer.masksToBounds = YES; @@ -74,8 +96,10 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event } else if (_frameManager.isDebugging) { if (CGRectContainsPoint(_button.frame,point)) { return _button; - } else if (CGRectContainsPoint(_slider.frame,point) && _souceView) { - return _slider; + } else if (CGRectContainsPoint(_layerSlider.frame,point) && _souceView) { + return _layerSlider; + } else if (CGRectContainsPoint(_distanceSlider.frame,point) && _souceView) { + return _distanceSlider; } else if (CGRectContainsPoint(_scrollView.frame,point) && _souceView) { return _scrollView; } @@ -88,15 +112,21 @@ - (void)setSouceView:(UIView *)souceView { _souceView = souceView; if (_souceView == nil) { - [[self.debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; - self.scrollView.hidden = YES; - self.slider.hidden = YES; + [[_debugLayers copy] makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; + _scrollView.hidden = YES; + _layerSlider.hidden = YES; + _distanceSlider.hidden = YES; } else { - self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); + _scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); [self scrollViewAddLayersInView:_souceView layerLevel:0 index:0]; - self.scrollView.hidden = NO; - self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); - self.slider.hidden = NO; + _scrollView.hidden = NO; + _scrollView.contentOffset = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0); + _layerSlider.hidden = NO; + _distanceSlider.hidden = NO; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.debugLayers enumerateObjectsUsingBlock:^(CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + }]; + }); } } @@ -105,7 +135,8 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel if ([view isKindOfClass:[UIView class]] && view) { if (view.superview) { UIView *cloneView = view.cloneView; - cloneView.layer.zPosition = -600 + (layerLevel*80+index*8); + cloneView.layer.zPosition = 0; + cloneView.layer.debug_zPostion = -600 + (layerLevel*80+index*8); cloneView.layer.masksToBounds = YES; CGRect frame = [view.superview convertRect:view.frame toView:_souceView]; @@ -114,25 +145,34 @@ - (void)scrollViewAddLayersInView:(UIView *)view layerLevel:(CGFloat)layerLevel cloneView.layer.opacity = 0.8; [self.debugLayers addObject:cloneView.layer]; [self.scrollView.layer addSublayer:cloneView.layer]; + + CABasicAnimation *theAnimation; + theAnimation=[CABasicAnimation animationWithKeyPath:@"zPosition"]; + theAnimation.fromValue=[NSNumber numberWithFloat:0]; + theAnimation.toValue=[NSNumber numberWithFloat:-600 + (layerLevel*80+index*8)]; + theAnimation.duration=1; + theAnimation.fillMode = kCAFillModeForwards; + theAnimation.removedOnCompletion = NO; + [cloneView.layer addAnimation:theAnimation forKey:@"zPosition"]; } - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - [self scrollViewAddLayersInView:obj layerLevel:layerLevel+1 index:idx]; - }]; - }); + [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [self scrollViewAddLayersInView:obj layerLevel:layerLevel+1 index:idx]; + }]; } } +#pragma mark - actions + - (void)showDifferentLayers:(float)percent { - CGFloat positionMax = self.debugLayers.firstObject.zPosition; + CGFloat positionMax = self.debugLayers.firstObject.debug_zPostion; CGFloat positionMin = positionMax; for (CALayer *layer in self.debugLayers) { - if (layer.zPosition >= positionMax) { - positionMax = layer.zPosition; + if (layer.debug_zPostion >= positionMax) { + positionMax = layer.debug_zPostion; } - if (layer.zPosition <= positionMin) { - positionMin = layer.zPosition; + if (layer.debug_zPostion <= positionMin) { + positionMin = layer.debug_zPostion; } } // 分成20节,每节为5 @@ -145,7 +185,7 @@ - (void)showDifferentLayers:(float)percent CGFloat dowmRange = positionMin + gap*(num-1); for (CALayer *layer in self.debugLayers) { - layer.opacity = (layer.zPosition>upRange || layer.zPositionupRange || layer.debug_zPostion