强制触摸后未在选择菜单项上调用选择器 [英] Selector not called on selecting menu item after force touch

查看:95
本文介绍了强制触摸后未在选择菜单项上调用选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,用于响应在强行触摸后点击菜单项的情况:

I have this code, for responding to a menu item being tapped after a force touch:

class InterfaceController: WKInterfaceController {
    override init() {
        super.init()

        self.addMenuItemWithItemIcon(WKMenuItemIcon.Pause, title: "Pause", action: Selector("test"))
    }

    func test() {
        print("test")
    }
}

当我强行触摸时,出现菜单.当我点击暂停"按钮时,不会调用test().

When I force touch, the menu appears. When I tap the "Pause" button, test() is not called.

为什么会这样?

推荐答案

已解决.

尽管这是一个愚蠢的错误(不是大多数问题吗?)的结果,但我认为很多人都会遇到这种情况,因此我将其保留在此处并给出答案.

Though its the result of a silly mistake (aren't most problems?), I think this is something a lot of people will run into, so I'll keep it here with my answer.

我在模拟器上启用了强制触摸,因此可以显示菜单.当我再次点击该按钮时,仍然启用强制触摸,因此我进行了强制触摸,因此关闭了菜单.

I enabled force touch on the simulator, so I could show the menu. When I'm tapping again on the button, force touch is still enabled, so I'm force touching, thus dismissing the menu.

解决方案:在点击菜单按钮之前禁用强制触摸.

这篇关于强制触摸后未在选择菜单项上调用选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆