NSView and Events

By default, the events (mouse/cursor/scroll...) are bypassed to the controls under the NSView, for example, there are one NSView (named A) and one NSTextField (named B). A and B are at same place, and A is above B.

  • All mouse events passed to B (TextField)
  • Cursor has been changed as "I", not the default cursor as expected
  • Scroll mouse will scroll B (the textfield if multiple lines)


I'd like that if mouse on A (the NSView), all the events are not passed to B. So I subclass NSView for A as the code following:

// ------------------------------------------------

class ResponsibleView: NSView {

override func acceptsFirstMouse(theEvent: NSEvent?) -> Bool {

return true

}


override var acceptsFirstResponder : Bool {

return true

}

override func mouseUp(theEvent: NSEvent) {

}

override func resetCursorRects() {

superview?.resetCursorRects()

self.addCursorRect(self.bounds, cursor: NSCursor.arrowCursor())

}


override func scrollWheel(theEvent: NSEvent) {

}

}

// ------------------------------------------------


Now there is a problem on cursor - the cursor is not stable, sometimes the cursor appears correctly, but sometimes incorrect. Would you please help to check following my questions?


- Is there simple solution to avoid events bypassing NSView?

- Why the cursor is too strange, how to make it be stable?

- Why the cocoa for OSX makes things too complicated and not be intuitive? ( I am new for OSX development), is there any modern UI solution for OSX like XAML ...


Thanks,

Replies

Were you able to find a solution to this?