有人可以花一秒钟给我指点吗?
我有一个 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);
}
重点是在窗口范围内清除,对吗?为什么它找不到视图?