任何“基本面向” NSScroller的例子在那里? [英] Any "fundamentals-oriented" example of NSScroller out there?

查看:116
本文介绍了任何“基本面向” NSScroller的例子在那里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个基本的,直接的例子,如何使用一对NSScrollers在NSScrollView与自定义NSView。

I'm looking for some kind of a basic, straightforward example of how to work with a pair of NSScrollers in an NSScrollView with a custom NSView.

有零星的例子,主要包括使用程序化创建的接口的假设示例,或基于开发人员使用典型的ImageView或TextView的假设。即使Sketch示例基于一个NSView,它使用打印对话框中的页面设置作为边界,并且一切都由Cocoa管理。所以没有真正的讨论或例子在任何地方如何使它使用自定义模型(虽然这可能是问题的一部分,因为一个基础是什么模型的工作?)。即使是苹果自己的文档也在这里。

There are sporadic examples out there, largely consisting of contrived examples using programatically created interfaces, or based on the assumption that the developer is working with a typical ImageView or TextView. Even the Sketch example is based on an NSView that uses the Page Setup in the Print dialog for the bounds, and everything is managed by Cocoa. So there's no real discussion or examples anywhere of how make it all work using a custom Model (though that may be part of the problem, because what does one base the Model on?). Even Apple's own documentation is dodgy here.

基本上,我有一个子类NSView包含在NSScrollView(根据Scoll View指南),用户可以点击视图创建,编辑和删除对象,很像一个插图程序。模型是那些只是数据包装器的对象,它们只是记录它们在drawRect:中的位置。

Essentially, I have a sub-classed NSView enbedded in an NSScrollView (per the Scoll View Guide), that a user can click in the view to create, edit and delete objects, much like an illustration program. The Model is those objects that are just data wrappers that simply record their position for drawRect: to use. The height and width are based on custom values that are being translated into pixels as needed.

我的问题是,我发现的所有示例都基于文本编辑器,图像查看器,或在页面设置对话框中使用标准文档大小。因为这些都是常见的文档类型,Cocoa基本上是为开发人员管理的,所以交互代码或多或少隐藏(或者我只是看不到它是什么)。我的项目不适合任何这些需求,我不需要打印。将我的模型推入documentView属性将不起作用。

My problem is that all of the examples I have found are based on either a text editor, an image viewer, or uses the standard document sizes in the Page Setup dialog. Because these are common document types, Cocoa basically manages for the developer, so the interaction code is more or less hidden (or I'm just not seeing it for what it is). My project doesn't fit any of those needs, and I have no need for printing. Thrusting my Model into the documentView property wouldn't work.

我只是在寻找一个简单的例子来说明如何使用一个自定义的,面向对象的Model(documentView)来初始化NSScrollers,并且基于对象的滚动和更新用户动作,例如当用户将一小部分对象拖动到左侧或下侧或窗口被调整大小时。我想我已经接近一起了,但是我错过了将控件与文档关联的跳转点。

I'm just looking for a simple example on how to initialize the NSScrollers with a custom, object-oriented Model (the documentView), and handle scrolling and updating based on user action, such as when the user drags a smattering of objects off to the left or down or the window gets resized. I think I'm close to getting it all together, but I'm missing the jumping off point that ties the controls to document.

(不是在可可性问题,但是当我在REALbasic中这样做时,我将简单计算并应用MaxX,MaxY到一个ScrollBar的最大值基于用户操作,在用户单击时观察ScrollBar中的位置,并根据需要绘制NSScrollers在NSScrollView上下文对我来说不是那么明显。)

(Not that it matters in a Cocoa question, but when I did this in REALbasic, I would simply calculate and apply the MaxX, MaxY to a ScrollBar's Maximum value based on user actions, watch the position in the ScrollBar when the user clicks, and draw as needed. NSScrollers in the NSScrollView context aren't nearly as obvious to me, it seems.)

我感谢大家的时间,但我更新了更多的信息希望得到一个答案,我可以使用。对不起,但没有一个是有意义的,苹果的文档是钝的,但也许我在这里失去了一些令人痛苦的明显...

I appreciate the time taken by everyone, but I'm updating with more information in the hopes of getting an answer I can use. I'm sorry, but none of this is making sense, Apple's documents are obtuse, but perhaps I'm missing something painfully obvious here...

我有一个数组的对象坐在一个子类NSDocument,这是数据保存者告诉drawRect什么和在哪里绘制。这是Sketch示例中的直接。 Sketch示例使用页面设置对话框中的文档大小作为大小,因此此处没有显示任何内容。我很酷的Cocoa处理滚动条的状态,但是如何链接ScrollView查看NSDocument中保存的初始编辑器的状态,并更新这些对象和编辑器?我计算我自己的NSRect并将其传递给NSScrollView?在哪里和如何?我在自定义NSView这是已经嵌入在NSScrollView或我的NSDocument在init中这样做? NSScrollView不是以编程方式创建的(没有简单的方法这样做),所以它都坐在Interface Builder等待被挂接。

I have an array of objects sitting in a subclassed NSDocument which are data holders that tell drawRect what and where to draw. This is straight from the Sketch example. The Sketch example uses the document sizes in the Page Setup dialog for the size, so there's nothing to show here. I'm cool with Cocoa handling the state of the scroll bars, but how do I link up the ScrollView to see the initial editor's state held in the NSDocument and updates to those objects and the editor? Do I calculate my own NSRect and pass that to the NSScrollView? Where and how? Am I doing this in my custom NSView which has been embedded in the NSScrollView or my NSDocument in init? The NSScrollView isn't created programmatically (there's no easy way of doing that), so it's all sitting in Interface Builder waiting to be hooked up. I'm missing the hook up bit.

也许我本周穿着我的我不能得到的帽子,但这不是这个难题。

Perhaps I'm wearing my "I don't get it" cap this week, but this can't be this difficult. Illustration apps, MIDI Editors, and countless other similar custom apps do this all the time.

SOLVED(主要):

我想我现在已经整理好了,虽然它可能不是最好的实现。

I think I have this sorted out now, though it's probably not the best implementation.

我的文档类现在有一个NSRect DocumentRect属性,它查看其所有对象并根据它们的位置返回一个新的NSRect。我调用它在我的子类NSView的鼠标事件与

My document class now has a NSRect DocumentRect property that looks at all of its objects and gives back a new NSRect based on their location. I call it in my subclassed NSView's mouse events with

[self setFrame:[[self EditorDocument] DocumentRect]];

这会根据用户交互更新视图的大小,现在窗口处理滚动的位置以前没有。在这一点上,我想出了如何让框架在拖动时展开,但至少我现在有了我缺少的基本概念。

This updates the size of the View based on user interaction, and the window now handles the scrolling where it didn't before. At this point I'm figuring out how to get the frame to expand while dragging, but at least I now have the fundamental concept I was missing.

给出的答案指向了我需要去的方向(documentView需要一个视图,翻译为查看NSView类),所以Peter获得了信用。非常感谢您的帮助。

The answer given pointed me in the direction I needed to go here (documentView requiring a view, which translated to looking at the NSView class), so Peter gets the credit. Thanks so much for help.

推荐答案

文档视图不是模型,它是一个视图。这就是为什么它被称为文档

The document view isn't a model, it's a view. That's why it's called the document view.

之所以有这么少的例子,直接使用NSScrollers是因为你通常不。

The reason there are so few examples on working with NSScrollers directly is because you normally don't. You work with NSScrollView and let it handle the scrollers for you.

所有你需要做的是使一个视图足够大,以显示整个模型,然后将其设置为文档视图的滚动视图。从那里,它应该是工作。你不需要自己管理任何滚动相关的数字; Cocoa会为您处理它们。

All you need to do is make a view big enough to show the entire model, then set that as the document view of the scroll view. From there, it should Just Work. You don't need to manage any of the scrolling-related numbers yourself; Cocoa handles them for you.

有关详情,请参阅 Scroll View Programming Guide

这篇关于任何“基本面向” NSScroller的例子在那里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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