【发布时间】:2013-02-01 16:41:16
【问题描述】:
有人可以花点时间给我指点吗?
我有一个 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);
}
重点是在窗口边界内清除,对吧?为什么找不到视图?
【问题讨论】:
标签: ios uiview uiwindow hittest