为什么我的观点相互重叠?

发布于 2024-11-05 07:05:25 字数 562 浏览 1 评论 0原文

我只是无法理解视图的事情,并且不知怎的找不到一个明确的解决方案。

我有一个视图“A”,它有一个按钮可以转到另一个视图“B”。视图 B 将我带到视图 C,视图 C 将我带回到 A。

在视图 C 中,用户点击的任何地方都会看到图像出现。其代码位于视图 C 的 .m 文件中。

问题是,当我从视图C切换到A时,C的代码仍然在视图A上运行?如果我点击 A,我会在点击的任何地方看到该图像,但 A 是我的菜单,而不是游戏的一部分。使图像出现在点击上的方法只属于视图C!

我无法理解这些观点;一开始我使用 insertSubview:atIndex: ,一切都是重叠的,所以现在我使用 addSubview: ,我遇到了这个问题。

有人可以从几何角度解释一下这是如何工作的吗?

为什么视图 C 中的按钮有时会无缘无故地出现在视图 A 中?为什么加载C回到A后,会在视图A上实现C的代码呢?

为什么我的观点总是重叠?我希望每个视图都能单独工作,并且不会从其背后的视图中看到任何内容,也不会从过去加载的视图中实现代码。

请帮我说说我的看法。多谢。

I just can't understand the views thing and somehow couldn't find one clear solution.

I have a view "A", and it has a button to go to another view "B". View B takes me to view C and view C takes me back to A.

In view C, everywhere that the user taps, he sees an image appear. The code for that is in view C's .m file.

The problem is that when I switch from view C to A, the code for C is still working on view A? If I tap on A, I see that image everywhere I tap, but A is my menu and not part of the game. The method that makes an image appear on a tap belongs only to view C!

I can't understand these views; at the start I used insertSubview:atIndex:, and everything was overlapping, so now I use addSubview:, and I have this problem.

Can some one explain geometrically how this works?

How come the buttons from view C are seen in view A somtimes without reason? Why, after loading C and back to A, it implements the code of C on view A?

Why do my views overlap all the time? I want every view to work seperately, and not see anything from the views behind it, or implement code from views that were loaded in the past.

Please, help me with my views. Thanks a lot.

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

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

发布评论

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

评论(2

兮颜 2024-11-12 07:05:25

您可能希望关注 UIViewController,而不是视图。有了这个,你就不会遇到这个问题了,UIViewController 几乎总是全屏的,你可以专门为其编写代码。您可以创建三个 UIViewController 子类,一个用于 A、B 和 C。在每个笔尖中,您可以添加一个按钮,并使用它来呈现下一个视图控制器(可能使用presentModalViewController:)。在第三个子类中,您可以实现在用户点击时显示图像的逻辑。

Rather than views, you probably want to focus on UIViewControllers. With this you won't have that problem, a UIViewController is almost always fullscreen and you can code specifically for it. You can create three UIViewController subclasses, one for A, B and C. In each's nib you can add a button, and use this to present the next view controller (possibly using presentModalViewController:). In the third subclass, you can implement your logic for showing an image when the user taps.

隔纱相望 2024-11-12 07:05:25

一个好的做法,假设你有一个

UIViewController *myViewController
有 3 个属性:

UIVIew *viewA

UIView *viewB

UIView *viewC

当你想显示将 viewA 放在堆栈上时,只需设置

myViewController.view = viewA;

等等!

One good practice, let say you have a

UIViewController *myViewController
with 3 properties :

UIVIew *viewA

UIView *viewB

UIView *viewC

When you want to diplay put a viewA on the stack just set

myViewController.view = viewA;

and so on!

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