Отслеживание, какое представление действительно полезно! Это может быть довольно тривиально, если вы знаете фрейм и какие суперслои и подслои связаны с этим представлением ... Если вы регистрируете все слои, то просто ищите и находите один и тот же адрес памяти. Удачи! :)
Добавить эту категорию в ваше приложение
Категория-Header:
#import "CALayer+debug.h"
@interface CALayer (Debug)
-(NSString*)debugDescription;
-(NSString*)debugLayerTree;
@end
Категория-Реализация:
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import "CALayer+debug.h"
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <objc/message.h>
@implementation CALayer (Debug)
//....
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
+ (void)swizzle {
Swizzle([self class], @selector(init), @selector(newInit));
}
- (id)newInit {
self = [self newInit];
[self performSelector:@selector(log) withObject:self afterDelay:0.5];
return self; // calls old method
}
- (void)log {
NSLog(@"%@", [self debugDescription]);
}
- (NSString *)debugDescription {
return [NSString stringWithFormat:@"%@ frame=%@ zAnchor=%1.1f, superlayer: %@>", [self description], NSStringFromCGRect(self.frame), self.zPosition, self.superlayer];
}
@end
Звонок, например, с AppDelegate
[CALayer swizzle];