简体   繁体   中英

NSWindow resize indicator not visible

How do I show resize indicators for an NSWindow without Titlebar?


I created a new Xcode project(for Mac app) with storyboard. I just disabled the checkbox Title Bar in Appearance(It hides the Title bar of NSwindow).

The strange thing was, after disabling the TitleBar, NSWindow was not showing resize indicators while mouse was above the window edges. Although if I drag at edges it was resizing.

I guess this is a bug, because if the window can be resized by dragging the mouse over edges, it must show the resize indicators.


图片

As it can be seen in the image, the resize indicators are seen after user drags the window, but many users would think that since there is no resize indicator, the window is not resizable.

I've fixed this issue by subclassing NSWindow and overriding canBecomeKeyWindow to return YES :

#import "MyWindow.h"

@implementation MyWindow

- (BOOL)canBecomeKeyWindow {
    return YES;
}

@end

Not updating resize cursors in this case looks like Apple bug. Documentation states "The value of canBecomeKeyWindow property is YES if the window has a title bar or a resize bar, or NO otherwise.", so I expect that canBecomeKeyWindow will return YES for resizable window. But it doesn't.

UPD: Checked on 10.10.5. Hopefully, you will have same behaviour on 10.11.

I have not checked this, but you could set the resize indicators manually. I think I would add four NSTrackingAreas to the windows contentView subclass (one for each side of the window, only few pixels in height/width). In the mouseEntered() method, create a new NSCursor object for the appropriate mouse position. Remember that the position could change, so use the mouseMoved() method as well. On mouseExited() reset the cursor.

Again, I have not tried this, but it should work.

PS: Don't forget to file a radar on this ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM