我应该如何使用多个 UIView 来表示屏幕上的区域?

发布于 2024-12-07 16:35:49 字数 354 浏览 0 评论 0原文

我正在构建一个 ipad 应用程序,屏幕上有两个基本区域:

  • 左侧的底座包含可以拖动到右侧的“东西” 右侧
  • 的自由形式画布

假设底座并且画布视图都作为子视图添加到视图控制器的视图中,我的问题是围绕用手指将“事物”从停靠栏拖动到画布上的机制......谁应该拥有代表“事物”的视图?是否应该是代表码头的 uiview(然后当它从码头移动到画布时,我将其从码头中删除并将其添加到画布中)?或者它应该属于视图控制器的根视图?或者其他一些模式?

我对人们对这里涉及的设计模式的想法感兴趣。

多谢。 顺便说一句,我已经考虑过使用像 cocos2d 这样的东西,但目前,我想继续使用标准 UIKit。

I am building an ipad app that has two basic regions on the screen:

  • A dock on the left hand side contains "things" that you can drag onto the right side
  • A free-form canvas on the right hand side

Under the presumption that the dock and the canvas views are both added as subviews to the viewcontroller's view, my question is around the mechanics of dragging the "thing" with my finger from the dock onto the canvas... who should own the view that represents the "thing"? Should it be the uiview that represents the dock (and then when it moves from the dock to the canvas I remove it from the dock and add it to the canvas)? Or should it belong the root view of the viewcontroller? Or some other pattern?

I'd be interested in peoples thoughts on the design patterns involved here.

Thanks a lot.
BTW, I've considered using something like cocos2d for this, but for the moment, I'd like to stay with the standard UIKit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2024-12-14 16:35:49

在 Objective-C 中,您使用 UIViewController 来控制视图。程序的逻辑驻留在这些控制器中。这个想法是分离视图和模型(数据)并让控制器管理交互。这称为MVC(“模型-视图-控制器”)设计模式

在您的情况下,控制器控制主视图及其子视图。因此,您可以在此处实现将一个对象(也是 UIView)从一个子视图拖动到另一个子视图的逻辑。用你的话来说,拖动的对象“属于”这个控制器。

也许您有另一个类来跟踪画布上的内容,即您的“数据模型”。控制器需要它来读取和写入更改。也许视图需要一些自定义绘图。视图将自行实现此行为。通过这种方式,您还可以遵循有助于编写可重用代码的封装原则。

In Objective-C, you use UIViewControllers to control views. The logic of the program resides in these controllers. The idea is to separate view and model (data) and have a controller managed the interaction. This is called the MVC ("Model-View-Controller") design pattern.

In your case, the controller controls the main view and its subviews. So it is exactly there where you would implement the logic of dragging one object (also a UIView) from one subview to another. In your words, the dragged object "belongs" to this controller.

Maybe you have another class that keeps track of the things on the canvas, your "data model". The controller would need that to read and write the changes to it. Maybe there is some custom drawing necessary for the views. The views would implement this behavior themselves. In this way, you also follow the principle of encapsulation that helps writing re-usable code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文