如何在 IB (iPhone/iPad) 中使用手势识别器?

发布于 2024-12-20 20:29:03 字数 452 浏览 3 评论 0原文

我刚刚在 IB 中发现了手势识别器,我想利用它们。我已经尝试过点击手势识别器,但它似乎不起作用。这是我所做的...

  1. 将“点击手势识别器”拖放到 IB 中的视图控制器中。

  2. 在 .m 文件中添加了以下方法...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender
    {
        // 做一些事情
    }
    
  3. 在.h文件中声明了该方法...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender;
    
  4. 最后我将 IBAction 链接到了 IB 中的“点击手势识别器”。

当我尝试运行它时,我没有成功 - 我是否错过了什么?

I have just discovered the Gesture Recognizers in IB and I would like to make use of them. I've tried out the Tap Gesture Recognizer however it doesn't seem to work. Here is what I've done...

  1. Dragged and dropped the 'Tap Gesture Recognizer' into my view controller in IB.

  2. Added the following method to the .m file...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender
    {
        // Do some stuff
    }
    
  3. Declared the method in the .h file...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender;
    
  4. Finally I linked up the IBAction to the 'Tap Gesture Recognizer' in IB.

When I tried running it I had no success - Have I missed something out?

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

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

发布评论

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

评论(3

天煞孤星 2024-12-27 20:29:03

按住 Control 键并单击笔尖中的手势识别器。在弹出窗口的“Referencing Outlet Collections”部分下,是否显示任何连接?它需要连接到视图的 gestureRecognizers 集合,如下所示:

connectionsspector

如果如果尚未连接,请将识别器拖到您想要将其附加到的视图上。您可以将其拖动到设计区域中的视图上,也可以将其拖动到左侧轮廓中的视图行上。

Control-click on the gesture recognizer in the nib. Under the "Referencing Outlet Collections" section of the popup, does it show any connections? It needs to be connected to the gestureRecognizers collection of your view, like this:

connections inspector

If it's not connected, drag the recognizer onto the view that you want it to be attached to. You can drag it onto the view in the design area, or you can drag it onto the view's row in the outline on the left.

哀由 2024-12-27 20:29:03

在属性检查器中,确保“状态”已启用,并选择“在视图中取消”和“延迟开始”事件。

In the attributes inspector, make sure State is Enabled and 'Canceled in View' and 'Delayed Begin' events are selected.

叹梦 2024-12-27 20:29:03

我在使用 UIImageView 时遇到手势识别器问题。为了使其正常工作,我必须检查 UIImageVIewuserInteractionEnabled

I was having problem with Gesture Recognizer with UIImageView. In order to get that worked, I had to check userInteractionEnabled of UIImageVIew.

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