Selector not called on selecting menu item after force touch

六眼飞鱼酱① 提交于 2019-12-10 13:04:43

问题


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")
    }
}

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

Any ideas why this might be?


回答1:


Solved.

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.

Solution: Disable force touch before tapping a menu button.




回答2:


I wanted to comment with my thanks for this solution but I don't have the rep so I'll begin with, THANKS!

However I can also add an addendum to the solution by pointing out the shortcut keys are really handy here for switching between force press pressures.

⇧⌘1 - for shallow pressure (tap)

⇧⌘2 - for deep pressure (force press)

Make sure the iOS Simulator (watch) is focussed and you'll be good to go.




回答3:


I'd like to add a small detail to make the SIM procedure more explicit because I actually saw this question and answer before and didn't perform it correctly because it wasn't totally obvious (to me at least).

  1. Press ⇧⌘1 for all regular presses.

  2. Press ⇧⌘2 before you use force touch.

  3. Tricky part: After the menu item appears press ⇧⌘1 again before dismissing the menu item!



来源:https://stackoverflow.com/questions/32359633/selector-not-called-on-selecting-menu-item-after-force-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!