gpt4 book ai didi

ios - 为什么 hitTest 不返回附加到窗口的 View ?

转载 作者:行者123 更新时间:2023-11-29 04:09:27 25 4
gpt4 key购买 nike

有人可以花一点时间给我指点吗?

我有一个附加到 UIWindow 的 UIView,并且我正在玩点的 hitTesting(原因比我想在这里讨论的要复杂得多)。

给定一个作为窗口 subview 附加的 View ,我希望 hitTest 能够找到该 View ,但它似乎没有:

- (void)test_hitTest_shouldFindTheViewAttachedToAWindow {
UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 210, 520)];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 200, 500)];
[window addSubview:view];

// This is ok
GHAssertEquals([view hitTest:CGPointMake(110, 270) withEvent:nil], view, nil);

// This fails: why? I would expect it to return the view, but it return null.
GHAssertEquals([view.window hitTest:CGPointMake(110, 270) withEvent:nil], view, nil);
}

重点是清除窗口的边界,对吧?为什么找不到 View ?

最佳答案

UIWindow 默认情况下创建为不可见,这意味着 hitTest:withEvent 将忽略它。如果您设置view.window.hidden = NO,那么hitTest:withEvent将按照您的预期工作。

关于ios - 为什么 hitTest 不返回附加到窗口的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14650975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com