有人可以花一秒钟给我一个指针吗?
我有一个UIView附加到UIWindow,我正在玩hitTesting积分(原因比我想要进入的复杂得多)。
如果附加一个视图作为窗口的子视图,我希望hitTest会找到该视图,但它似乎不会出现:
- (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);
}
关键是在窗口范围内清除,对吧?为什么不找到这个观点?
答案 0 :(得分:1)
UIWindow
创建为不可见,这意味着hitTest:withEvent
会忽略它。如果您设置view.window.hidden = NO
,则hitTest:withEvent
将按预期工作。