SatanWoo/TrampolineHook

检测是否在非主线程操作UI 2个问题

SilenceZhou opened this issue · 0 comments

1、为啥是检测 UIResponder 及其子类的方法,而不是监测 UIView类及其子类呢?

2、MainThreadChecker 中 MTInitializer 循环打印问题?

在 ViewController.m 添加测试代码,出现循环打印问题, 测试代码如下

`

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(){
    UIView *v = [UIView new];
    [self.view addSubview:v];
    });
    }
    循环打印结果:
    2023-02-02 16:53:46.189278+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector clipsToBounds
    2023-02-02 16:53:46.189307+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.189481+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector layer
    2023-02-02 16:53:46.189510+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.189636+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector alpha
    2023-02-02 16:53:46.189667+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.189797+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector isHidden
    2023-02-02 16:53:46.189825+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.189933+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector isOpaque
    2023-02-02 16:53:46.189953+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190060+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector autoresizingMask
    2023-02-02 16:53:46.190150+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190266+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector autoresizesSubviews
    2023-02-02 16:53:46.190333+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190489+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector isUserInteractionEnabled
    2023-02-02 16:53:46.190518+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190643+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector _interactionTintColor
    2023-02-02 16:53:46.190674+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190822+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector isFocused
    2023-02-02 16:53:46.190843+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.190886+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector _focusSystem
    2023-02-02 16:53:46.190974+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.191059+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector transform
    2023-02-02 16:53:46.191169+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.191329+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector frame
    2023-02-02 16:53:46.191355+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.191405+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector transform
    2023-02-02 16:53:46.191455+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.191689+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector transform3D
    2023-02-02 16:53:46.191769+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.191904+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector layer
    2023-02-02 16:53:46.192584+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.192964+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector _shouldAppendTextInViewDescription
    2023-02-02 16:53:46.193021+0800 MainThreadCheckerExample[2549:862607]
    2023-02-02 16:53:46.193064+0800 MainThreadCheckerExample[2549:862607] [MTMainThreadChecker]::Found issue on <UIView: 0x1032058c0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)> with selector clipsToBounds
    `