objective c - updateTrackingAreas: override only works for the first 2 times? -
on el capitan in xcode 7 beta using swift 2.0, subclassed nsview
use prototype view of nscollectionview
's item view, , override updatetrackingareas:
method mouse tracking. nscollectionview
inside nspopover
.
it seems first 2 times updatetrackingareas:
called, debug log shows. code following:
override func updatetrackingareas() { swift.print("updatetrackingareas:") if trackingarea != nil { self.removetrackingarea(trackingarea!) } trackingarea = nstrackingarea( rect: self.bounds, options: [nstrackingareaoptions.mouseenteredandexited, nstrackingareaoptions.activealways], owner: self, userinfo: nil ) if trackingarea != nil { self.addtrackingarea(trackingarea!) } var mouselocation = self.window?.mouselocationoutsideofeventstream mouselocation = self.convertpoint(mouselocation!, fromview: nil) if cgrectcontainspoint(self.bounds, mouselocation!) { mouseentered(nsevent()) } else { mouseexited(nsevent()) } super.updatetrackingareas() }
the first 2 times when popover opened, can see console log shows updatetrackingareas:
. tracking failed , no logs either.
edit:
when commented out part like:
//var mouselocation = self.window?.mouselocationoutsideofeventstream mouselocation = self.convertpoint(mouselocation!, fromview: nil) if cgrectcontainspoint(self.bounds, mouselocation!) { mouseentered(nsevent()) } else { mouseexited(nsevent()) }
the problem no longer exists.
and following code makes no differences:
if let window = self.window { var mouselocation = window.mouselocationoutsideofeventstream mouselocation = self.convertpoint(mouselocation, fromview: nil) if let event = nsapplication.sharedapplication().currentevent { if nspointinrect(mouselocation, self.bounds) { mouseentered(event) } else { mouseexited(event) } } }
edit 2:
ok, reinstall os x yosemite , compiled again xcode 7 beta 1. problem no longer exists. might bug of el capitan. i'll report apple. thank all.
you're passing newly-created event instance mouseentered()
, mouseexited()
. realize because can't pass nil in swift variant of method perhaps should pass current event instead (nsapplication
, nswindow
both have currentevent()
method). have tried this?
Comments
Post a Comment