osx-yosemitedrawrectcocoa-bindingswindow-style

OS X Yosemite window style mask NSFullSizeContentViewWindowMask cause only clicked button of collection view can call drawRect


My environment is OS X Yosemite 10.10.2. Xcode are 6.1.1 and 6.2 beta4. I wrote an calendar app for OS X. I used a cocoa bindings framework that I wrote. And I got a problem. There should be only one focus day button in the collection view. But something wrong. The app has multiple focuses.

I found a statement cause this problem. [[[self view] window] setStyleMask:([[self view] window].styleMask | NSFullSizeContentViewWindowMask)]; When app sets the NSFullSizeContentViewWindowMask, only the clicked button of collection view will call drawRect because of performance. This caused my problem. - (void)drawRect:(NSRect)dirtyRect

The related post in Apple developer forum:https://devforums.apple.com/message/1097305#1097305


Solution

  • I found a solution. In the "- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;" of button add "[self setNeedsDisplay:YES ];"

    The original tutorial of cocoa bindings, observeValueForKeyPath action has [self setNeedsDisplay :YES]; But I don't remember that why I commented it. When NSFullSizeContentViewWindowMask not set, the app just got only one focus.