Objective C:我可以将子视图设置为firstResponder吗?

发布于 2024-11-14 12:40:34 字数 404 浏览 2 评论 0原文

我遇到一种情况,我将另一个视图控制器的视图添加到现有的视图控制器。例如:

//set up loading page
self.myLoadingPage = [[LoadingPageViewController alloc]init ];
self.myLoadingPage.view.frame = self.view.bounds;
self.myLoadingPage.view.hidden = YES;

[self.view addSubview:self.myLoadingPage.view];

是否可以将“self.myLoadingPage”设置为第一响应者?在这种情况下,加载页面视图大小不会覆盖现有视图的整个大小,并且用户仍然可以与超级视图交互(这不是所需的行为)。在这种情况下我只想启用子视图。

I have a situation whereby I am adding a view from another viewcontroller to an existing viewcontroller. For example:

//set up loading page
self.myLoadingPage = [[LoadingPageViewController alloc]init ];
self.myLoadingPage.view.frame = self.view.bounds;
self.myLoadingPage.view.hidden = YES;

[self.view addSubview:self.myLoadingPage.view];

Is it possible to set 'self.myLoadingPage' to be the first responder? This is the case whereby the loadingpage view size does not cover the entire size of the existing view and users can still interact with the superview (which is not the desired behaviour). I want to just enable the subview in this case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风筝有风,海豚有海 2024-11-21 12:40:34

当我遇到类似的问题时,我制作了一个覆盖整个屏幕的不可见 UIView,我在主视图顶部添加了大型不可见 UIView,并使加载视图成为不可见 UIView 的子视图。

When I had a similar problem, I made an invisible UIView that covered the entire screen, I added the large invisible UIView on top of the main view and made the loading view a subview of the invisible UIView.

另类 2024-11-21 12:40:34

最简单的解决方案是重写加载视图中的 hitTest 方法以返回 TRUE。该顶视图位于响应者链中的第一个,调用 hitTest 方法,如果该点位于视图内并且因此将被处理,则该方法通常返回 TRUE,无论返回 TRUE 意味着您获得触摸事件并有效阻止消息重新发送到下一个响应者。

The simplest solution is to override hitTest method in your loading view to return TRUE. This top view is first in the responder chain, the hitTest method gets called which NORMALLY returns TRUE if the point is within the view and will therefore be handled, returning TRUE regardless means you get the touch event and effectively block the message being resent to the next responder.

一袭白衣梦中忆 2024-11-21 12:40:34

有趣的问题。我发现了类似的帖子,其中引用了Apple开发者论坛的内容这个问题:

真正让这个视图成为唯一的东西
在可以接收触摸的屏幕上
你需要添加另一个视图
超越一切
其余的触摸,或子类 a
查看层次结构中的某个位置(或
你的 UIWindow 本身)并覆盖
hitTest:withEvent: 始终返回
当文本视图可见时,或者
对于不在你的范围内的触摸返回 nil
文本视图。

这似乎表明没有一个非常简单的解决方案(除非 2010 年 10 月之后对此进行了 API 更改。)

或者,我想您可以浏览您的应用程序中的所有其他 subviews superview 并单独将其 userInteractionEnabled 属性设置为 NO (但这可能比引用的解决方案更麻烦)。

我很想看到其他方法来实现这一点。

Interesting question. I found a similar post with a quote from the Apple Developer Forums on this issue:

To truly make this view the only thing
on screen that can receive touches
you'd need to either add another view
over top of everything else to catch
the rest of the touches, or subclass a
view somewhere in your hierarchy (or
your UIWindow itself) and override
hitTest:withEvent: to always return
your text view when it's visible, or
to return nil for touches not in your
text view.

This would seem to indicate there isn't a terribly straightforward solution (unless there was an API change regarding this made after October, 2010.)

Alternatively, I suppose you could go through all the other subviews in your superview and individually set their userInteractionEnabled properties to NO (but that would probably prove more cumbersome than the quoted solutions).

I would love to see other ways to allow this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文