mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 04:17:17 +00:00
feature: Weex APM
This commit is contained in:
@@ -292,89 +292,89 @@ static char *ua_viewController_close_time = "ua_viewController_close_time";
|
||||
|
||||
当然有解决方案啦。
|
||||
|
||||
- 找出当前元素在父层同类型元素中的索引。根据当前的元素遍历当前元素的父级元素的子元素,如果出现相同的元素,则需要判断当前元素是所在层级的第几个元素
|
||||
找出当前元素在父层同类型元素中的索引。根据当前的元素遍历当前元素的父级元素的子元素,如果出现相同的元素,则需要判断当前元素是所在层级的第几个元素
|
||||
|
||||
对当前的控件元素的父视图的全部子视图进行遍历,如果存在和当前的控件元素同类型的控件,那么需要判断当前控件元素在同类型控件元素中的所处的位置,那么则可以唯一定位。举例:`GoodsCell-3.GoodsTableView.GoodsViewController.xxApp`
|
||||
对当前的控件元素的父视图的全部子视图进行遍历,如果存在和当前的控件元素同类型的控件,那么需要判断当前控件元素在同类型控件元素中的所处的位置,那么则可以唯一定位。举例:`GoodsCell-3.GoodsTableView.GoodsViewController.xxApp`
|
||||
|
||||
```Objective-c
|
||||
```Objective-c
|
||||
//UIResponder分类
|
||||
- (NSString *)ua_identifierKa
|
||||
{
|
||||
// if (self.xq_identifier_ka == nil) {
|
||||
if ([self isKindOfClass:[UIView class]]) {
|
||||
UIView *view = (id)self;
|
||||
NSString *sameViewTreeNode = [view obtainSameSuperViewSameClassViewTreeIndexPath];
|
||||
NSMutableString *str = [NSMutableString string];
|
||||
//特殊的 加减购 因为带有spm但是要区分加减 需要带TreeNode
|
||||
NSString *className = [NSString stringWithUTF8String:object_getClassName(view)];
|
||||
if (!view.accessibilityIdentifier || [className isEqualToString:@"uaButton"]) {
|
||||
[str appendString:sameViewTreeNode];
|
||||
[str appendString:@","];
|
||||
}
|
||||
while (view.nextResponder) {
|
||||
[str appendFormat:@"%@,", NSStringFromClass(view.class)];
|
||||
if ([view.class isSubclassOfClass:[UIViewController class]]) {
|
||||
break;
|
||||
}
|
||||
view = (id)view.nextResponder;
|
||||
}
|
||||
self.xq_identifier_ka = [self md5String:[NSString stringWithFormat:@"%@",str]];
|
||||
// self.xq_identifier_ka = [NSString stringWithFormat:@"%@",str];
|
||||
}
|
||||
// }
|
||||
return self.xq_identifier_ka;
|
||||
}
|
||||
|
||||
// UIView 分类
|
||||
- (NSString *)obtainSameSuperViewSameClassViewTreeIndexPat
|
||||
{
|
||||
NSString *classStr = NSStringFromClass([self class]);
|
||||
//cell的子view
|
||||
//UITableView 特殊的superview (UITableViewContentView)
|
||||
//UICollectionViewCell
|
||||
BOOL shouldUseSuperView =
|
||||
([classStr isEqualToString:@"UITableViewCellContentView"]) ||
|
||||
([[self.superview class] isKindOfClass:[UITableViewCell class]])||
|
||||
([[self.superview class] isKindOfClass:[UICollectionViewCell class]]);
|
||||
if (shouldUseSuperView) {
|
||||
return [self obtainIndexPathByView:self.superview];
|
||||
}else {
|
||||
return [self obtainIndexPathByView:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)obtainIndexPathByView:(UIView *)view
|
||||
{
|
||||
NSInteger viewTreeNodeDepth = NSIntegerMin;
|
||||
NSInteger sameViewTreeNodeDepth = NSIntegerMin;
|
||||
|
||||
NSString *classStr = NSStringFromClass([view class]);
|
||||
|
||||
NSMutableArray *sameClassArr = [[NSMutableArray alloc]init];
|
||||
//所处父view的全部subviews根节点深度
|
||||
for (NSInteger index =0; index < view.superview.subviews.count; index ++) {
|
||||
//同类型
|
||||
if ([classStr isEqualToString:NSStringFromClass([view.superview.subviews[index] class])]){
|
||||
[sameClassArr addObject:view.superview.subviews[index]];
|
||||
}
|
||||
if (view == view.superview.subviews[index]) {
|
||||
viewTreeNodeDepth = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//所处父view的同类型subviews根节点深度
|
||||
for (NSInteger index =0; index < sameClassArr.count; index ++) {
|
||||
if (view == sameClassArr[index]) {
|
||||
sameViewTreeNodeDepth = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [NSString stringWithFormat:@"%ld",sameViewTreeNodeDepth];
|
||||
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
- (NSString *)ua_identifierKa
|
||||
{
|
||||
// if (self.xq_identifier_ka == nil) {
|
||||
if ([self isKindOfClass:[UIView class]]) {
|
||||
UIView *view = (id)self;
|
||||
NSString *sameViewTreeNode = [view obtainSameSuperViewSameClassViewTreeIndexPath];
|
||||
NSMutableString *str = [NSMutableString string];
|
||||
//特殊的 加减购 因为带有spm但是要区分加减 需要带TreeNode
|
||||
NSString *className = [NSString stringWithUTF8String:object_getClassName(view)];
|
||||
if (!view.accessibilityIdentifier || [className isEqualToString:@"uaButton"]) {
|
||||
[str appendString:sameViewTreeNode];
|
||||
[str appendString:@","];
|
||||
}
|
||||
while (view.nextResponder) {
|
||||
[str appendFormat:@"%@,", NSStringFromClass(view.class)];
|
||||
if ([view.class isSubclassOfClass:[UIViewController class]]) {
|
||||
break;
|
||||
}
|
||||
view = (id)view.nextResponder;
|
||||
}
|
||||
self.xq_identifier_ka = [self md5String:[NSString stringWithFormat:@"%@",str]];
|
||||
// self.xq_identifier_ka = [NSString stringWithFormat:@"%@",str];
|
||||
}
|
||||
// }
|
||||
return self.xq_identifier_ka;
|
||||
}
|
||||
|
||||
// UIView 分类
|
||||
- (NSString *)obtainSameSuperViewSameClassViewTreeIndexPat
|
||||
{
|
||||
NSString *classStr = NSStringFromClass([self class]);
|
||||
//cell的子view
|
||||
//UITableView 特殊的superview (UITableViewContentView)
|
||||
//UICollectionViewCell
|
||||
BOOL shouldUseSuperView =
|
||||
([classStr isEqualToString:@"UITableViewCellContentView"]) ||
|
||||
([[self.superview class] isKindOfClass:[UITableViewCell class]])||
|
||||
([[self.superview class] isKindOfClass:[UICollectionViewCell class]]);
|
||||
if (shouldUseSuperView) {
|
||||
return [self obtainIndexPathByView:self.superview];
|
||||
}else {
|
||||
return [self obtainIndexPathByView:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)obtainIndexPathByView:(UIView *)view
|
||||
{
|
||||
NSInteger viewTreeNodeDepth = NSIntegerMin;
|
||||
NSInteger sameViewTreeNodeDepth = NSIntegerMin;
|
||||
|
||||
NSString *classStr = NSStringFromClass([view class]);
|
||||
|
||||
NSMutableArray *sameClassArr = [[NSMutableArray alloc]init];
|
||||
//所处父view的全部subviews根节点深度
|
||||
for (NSInteger index =0; index < view.superview.subviews.count; index ++) {
|
||||
//同类型
|
||||
if ([classStr isEqualToString:NSStringFromClass([view.superview.subviews[index] class])]){
|
||||
[sameClassArr addObject:view.superview.subviews[index]];
|
||||
}
|
||||
if (view == view.superview.subviews[index]) {
|
||||
viewTreeNodeDepth = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//所处父view的同类型subviews根节点深度
|
||||
for (NSInteger index =0; index < sameClassArr.count; index ++) {
|
||||
if (view == sameClassArr[index]) {
|
||||
sameViewTreeNodeDepth = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [NSString stringWithFormat:@"%ld",sameViewTreeNodeDepth];
|
||||
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user