Mouse events (NSTrackingArea) in Playground not working

北战南征 提交于 2019-12-22 17:28:13

问题


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.

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

回答1:


According to this 2014 WWDC session:

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.

You can find the original video here



来源:https://stackoverflow.com/questions/34442116/mouse-events-nstrackingarea-in-playground-not-working

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