如何在 iOS 中创建自定义目标/操作
我有两个视图 A 和 B。它们位于同一控制器中,作为主 UIVIew 的子视图。视图 A 有一个按钮。我希望该按钮在被触摸时抛出一个事件,该事件将由视图 B 监听。我应该如何做到这一点?
I have two views A and B. They are booth in the same controller as subviews of a main UIVIew. View A has a button. I want that button to throw an event when it gets touched which will be listen by view B. How should I make that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会假设你的观点A& B 是 UIView(而不是 UIView 的子类,您可以通过将视图 A 设为 UIButton 来简化操作)。所以,我想最简单的解决方案是创建一个 UITapGestureRecognizer 并将其回调挂接到您的其他视图。
基本上是这样的:
I'll assume your views A & B are UIViews (instead of, maybe, subclasses of UIView where you could simplify things by making view A an UIButton). So, I guess the simplest solution would be to create an UITapGestureRecognizer and hook its callback to your other view.
Basically, something like this: