Skip to content

2.3&2.4查看UI层次时Xcode崩溃 #9

@Dilrvvr

Description

@Dilrvvr

2.3&2.4在demo中无法查看UI层次,在我们的项目中表现为查看层次时Xcode崩溃。

应该是window不能addSubview另一个window,对应出问题代码在 WHDebugToolManager.m 文件中-setDebugWindow 方法的[KDebugCurrentWindow addSubview:self.debugWindow];这一行。

建议修改如下:

- (void)setDebugWindow {
    
    if (self.debugWindow) { return; }
    
    CGFloat debugWindowY = debugTool_iPhoneX() ? 30 : 0;
    self.debugWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, debugWindowY, kDebugScreenWidth, kDebugLabelHeight)];
    self.debugWindow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    self.debugWindow.windowLevel = UIWindowLevelAlert;
    self.debugWindow.rootViewController = [WHDebugTempVC new];
    self.debugWindow.hidden = NO;
    //[KDebugCurrentWindow addSubview:self.debugWindow];
    
    // 注册window
    if (@available(iOS 13.0, *)) {
        
        for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
            
            if (windowScene.activationState == UISceneActivationStateForegroundActive) {
                
                self.debugWindow.windowScene = windowScene;
                
                break;
            }
        }
        
        __weak typeof(self) weakSelf = self;
        
        [[NSNotificationCenter defaultCenter] addObserverForName:UISceneWillConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
            
            UIWindowScene *windowScene = note.object;
            
            if (![windowScene isKindOfClass:[UIWindowScene class]]) { return; }
            
            weakSelf.debugWindow.windowScene = windowScene;
        }];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions