简体   繁体   English

NSWindow调整指标不可见

[英]NSWindow resize indicator not visible

How do I show resize indicators for an NSWindow without Titlebar? 如何在没有Titlebar的情况下显示NSWindow的resize indicators


I created a new Xcode project(for Mac app) with storyboard. 我用故事板创建了一个新的Xcode项目(适用于Mac应用程序)。 I just disabled the checkbox Title Bar in Appearance(It hides the Title bar of NSwindow). 我只是禁用该复选框Title Bar的外观(它隐藏NSwindow的标题栏)。

The strange thing was, after disabling the TitleBar, NSWindow was not showing resize indicators while mouse was above the window edges. 奇怪的是,在禁用TitleBar后,当鼠标高于窗口边缘时,NSWindow没有显示调整大小指示器。 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 : 我通过canBecomeKeyWindow NSWindow并重写canBecomeKeyWindow来修复此问题,返回YES

#import "MyWindow.h"

@implementation MyWindow

- (BOOL)canBecomeKeyWindow {
    return YES;
}

@end

Not updating resize cursors in this case looks like Apple bug. 在这种情况下不更新调整大小游标看起来像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. 文档说明“如果窗口有标题栏或调整大小条,则canBecomeKeyWindow属性的值为YES ,否则为NO 。”,所以我希望canBecomeKeyWindow将为可调整大小的窗口返回YES But it doesn't. 但事实并非如此。

UPD: Checked on 10.10.5. UPD:检查10.10.5。 Hopefully, you will have same behaviour on 10.11. 希望你在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). 我想我会在windows contentView子类中添加四个NSTrackingAreas(一个用于窗口的每一侧,高度/宽度只有几个像素)。 In the mouseEntered() method, create a new NSCursor object for the appropriate mouse position. 在mouseEntered()方法中,为适当的鼠标位置创建一个新的NSCursor对象。 Remember that the position could change, so use the mouseMoved() method as well. 请记住,位置可能会发生变化,因此也请使用mouseMoved()方法。 On mouseExited() reset the cursor. 在mouseExited()上重置光标。

Again, I have not tried this, but it should work. 我再次尝试过,但它应该可行。

PS: Don't forget to file a radar on this ;) PS:不要忘记为此提交雷达;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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