定位NSTextView的检查器栏 [英] Positioning inspector bar for NSTextView

查看:219
本文介绍了定位NSTextView的检查器栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

轻松启用文本视图的检查栏,以便使用各种格式化按钮在屏幕顶部显示栏。 (虽然我有一些困惑,直到我学会确保我在滚动视图中选择文本视图,而不是滚动视图本身)。我可以以编程方式使用[textView setUsesInspectorBar:YES]或转到属性检查器,并检查使用部分中的检查器栏框。



,我如何进一步控制检查栏?我在XCode文档或在线查找有关它的信息。我想能够将它放在屏幕上的不同位置。

解决方案

答案是,你不能在 t旨在进一步控制检查栏。文档中没有什么,因为,没有什么。 。



然而,如果你深入探讨它,你会发现检查员bar是一个非常有趣的控件。它不会显示为文本视图的一部分,而是(私人地)嵌入在窗口视图本身。



如果您列出该窗口视图的子视图:

  NSLog(@%@,[self.testTextView.window.contentView superview] .subviews); 

您最终得到:

  2012-08-02 15:59:30.145示例[16702:303](
< _NSThemeCloseWidget:0x100523dc0>,//关闭按钮
_NSThemeWidget:0x100525ce0>,//最小化按钮?
< _NSThemeWidget:0x100524e90>,//最大化按钮?
< NSView:0x100512ad0& b $ b< __ NSInspectorBarView:0x100529d50>,//检查器视图
(< NSToolbarView:0x10054e650>:FD2E0533-AB18-4E7E-905A-AC816CB80A26)//工具栏

如您所见, AppKit 检查栏与其他顶级窗口控件处于同一级别。现在这是进入私人API的土地,但只是修改窗口视图不应该得到任何应用程序拒绝。






您可以 从此处获取对 __ NSInspectorBarView 的引用。看起来总是子视图在内容视图之后,所以这样的东西可能工作:

  NSArray * topLevelViews = self.testTextView.window.contentView superview] .subviews; 
NSUInteger indexOfContentView = [topLevelViews indexOfObject:self.testTextView.window.contentView];
if(indexOfContentView + 1< topLevelViews.count){
NSView * inspectorBar = [topLevelViews objectAtIndex:indexOfContentView + 1];
NSLog(@%@,inspectorBar);
}
NSLog(@%@,topLevelViews);

因为如果苹果改变顶级视图的顺序,这会立即中断,它可能不是一个好的生产应用的想法。另一个想法是:

  NSView * inspectorBarView = nil; 
for(NSView * topLevelView in topLevelViews){
if([topLevelView isKindOfClass:NSClassFromString(@__ NSInspectorBarView)]){
inspectorBarView = topLevelView;
}
}
NSLog(@%@,inspectorBarView);

我不知道是否使用 NSClassFromString






那么,我们将通过App Store审查指南,一旦你得到一个参考检查栏视图,事情仍然不能很好地工作。您可以尝试在底部重新定位它:

  if(inspectorBarView){
NSRect newFrame = inspectorBarView.frame;
newFrame.origin = NSZeroPoint;
[inspectorBarView setAutoresizingMask:NSViewMaxYMargin | NSViewMaxXMargin];
[inspectorBarView setFrame:newFrame];
}

但是你最终会出现一个错误的工具栏,所以需要更多的工作:



>



我的想法是尝试移动内容视图的高度,以覆盖灰色左边区域(这将必须在每次窗口调整大小,可能修改



编辑可以让自动调整掩码变得更容易) b

哦,你也应该提交一个功能请求。 bugreport.apple.com


It's easy to enable the "inspector bar" for text views so that a bar appears at the top of the screen with various formatting buttons. (Although I had some confusion until I learned to make sure I was selecting the text view in a scroll view, and not the scroll view itself). I can either programmatically use [textView setUsesInspectorBar:YES] or go to the Attributes Inspector and check the "Inspector Bar" box in the "Uses" section.

My question is, how can I further control the inspector bar? I'm having trouble finding information on it in the XCode documentation or online. I'd like to be able to position it in a different place on the screen. Being able to pick and choose which specific controls are in the bar would be great too.

解决方案

The answer is, you aren't meant to further control the inspector bar. There's nothing in the documentation because, well, there's nothing. Apple's saying, use it or don't use it.

However, if you dig into it a bit, you will find that the inspector bar is a very interesting control. It's not displayed as part of the text view, but rather (privately) embedded in the "window view" itself. When I say "window view," I mean the superview of the content view.

If you list the subviews of that "window view":

NSLog(@"%@", [self.testTextView.window.contentView superview].subviews);

You end up with:

2012-08-02 15:59:30.145 Example[16702:303] (
    "<_NSThemeCloseWidget: 0x100523dc0>", // the close button
    "<_NSThemeWidget: 0x100525ce0>", // the minimize button?
    "<_NSThemeWidget: 0x100524e90>", // the maximize button?
    "<NSView: 0x100512ad0>", // the content view
    "<__NSInspectorBarView: 0x100529d50>", // the inspector view
    "(<NSToolbarView: 0x10054e650>: FD2E0533-AB18-4E7E-905A-AC816CB80A26)" // the toolbar
)

As you can see, AppKit puts the inspector bar at the same level as other top level window controls. Now this is getting into the land of private APIs, but simply tinkering with the "window view" shouldn't get any apps rejected.


You can try to get a reference to the __NSInspectorBarView from here. It seems like it is always the subview right after the content view, so something like this may work:

NSArray *topLevelViews = [self.testTextView.window.contentView superview].subviews;
NSUInteger indexOfContentView = [topLevelViews indexOfObject:self.testTextView.window.contentView];
if (indexOfContentView + 1 < topLevelViews.count) {
    NSView *inspectorBar = [topLevelViews objectAtIndex:indexOfContentView + 1];
    NSLog(@"%@", inspectorBar);
}
NSLog(@"%@", topLevelViews);

Since this immediately breaks if Apple changes the ordering of the top level views, it may not be a good idea for an application for production. Another idea is:

NSView *inspectorBarView = nil;
for (NSView *topLevelView in topLevelViews) {
    if ([topLevelView isKindOfClass:NSClassFromString(@"__NSInspectorBarView")]) {
        inspectorBarView = topLevelView;
    }
}
NSLog(@"%@", inspectorBarView);

I don't know if the use of NSClassFromString() will pass App Store review guidelines, however, since once again, it's dependent on private APIs.


That being said, once you get a reference to the inspector bar view, things still don't work too well. You can try repositioning it at the bottom:

if (inspectorBarView) {
    NSRect newFrame = inspectorBarView.frame;
    newFrame.origin = NSZeroPoint;
    [inspectorBarView setAutoresizingMask:NSViewMaxYMargin | NSViewMaxXMargin];
    [inspectorBarView setFrame:newFrame];
}

But you end up with a misdrawn toolbar, so more work would be necessary there:

My ideas would be to try to shift the content view's height up to cover up the gray left-over area (which would have to be done every time the window is resized, maybe tinkering with autoresizing masks may make it easier) and custom draw a background for the inspector bar at the bottom.

EDIT

Oh, and you should file a feature request for this too. bugreport.apple.com

这篇关于定位NSTextView的检查器栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆