Objective C:我可以将子视图设置为firstResponder吗?
我遇到一种情况,我将另一个视图控制器的视图添加到现有的视图控制器。例如:
//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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我遇到类似的问题时,我制作了一个覆盖整个屏幕的不可见 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.
最简单的解决方案是重写加载视图中的 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.
有趣的问题。我发现了类似的帖子,其中引用了Apple开发者论坛的内容这个问题:
这似乎表明没有一个非常简单的解决方案(除非 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:
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 yoursuperview
and individually set theiruserInteractionEnabled
properties toNO
(but that would probably prove more cumbersome than the quoted solutions).I would love to see other ways to allow this.