游乐场中的鼠标事件(NSTrackingArea)不起作用 [英] Mouse events (NSTrackingArea) in Playground not working

查看:28
本文介绍了游乐场中的鼠标事件(NSTrackingArea)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSView 的子类,它包含以下 NSTrackingArea 代码.但出于某种原因,鼠标事件不会在 Playground 中触发.

I have a a subclass of NSView which contains the following NSTrackingArea code. But for some reason the mouse events won't trigger in Playground.

正在调用 viewWillMoveToWindow,但似乎没有其他任何东西触发.有没有人知道缺少什么?

The viewWillMoveToWindowis being called, but nothing else seems to fire. Does anyone have a clue to what is missing?

class MyView: NSView {

    private var trackingArea: NSTrackingArea    = NSTrackingArea()

    // Other stuff omitted here...
    // ...

    override func viewWillMoveToWindow(newWindow: NSWindow?) {

        // Setup a new tracking area when the view is added to the window.
         trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited, .ActiveAlways], owner: self, userInfo: nil)
         self.addTrackingArea(trackingArea)
    }
    override func updateTrackingAreas() {

          self.removeTrackingArea(trackingArea)

          trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited, .ActiveAlways], owner: self, userInfo: nil)
          self.addTrackingArea(trackingArea)
    }

    // Mouse events
    override func mouseEntered(theEvent: NSEvent) {

         NSLog("MouseEntered")
    }
     override func mouseExited(theEvent: NSEvent) {

         NSLog("MouseExited")
    }
     override func mouseDown(theEvent: NSEvent) {

         NSLog("MouseDown")
    }
}

推荐答案

根据 this 2014WWDC 会议:

According to this 2014 WWDC session:

Playgrounds 有更多限制.Playgrounds 不能用于需要用户交互的事物.因此,我们非常支持显示实时视图,但您只能看到它们,不能触摸它们.

There are few more limitations with Playgrounds. Playgrounds cannot be used for things which require user interaction. So we have great support for showing live views but you can only see them, you can't touch them.

您可以在此处

这篇关于游乐场中的鼠标事件(NSTrackingArea)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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