简体   繁体   English

在子视图的内部边界内移动ImageView

[英]Moving an ImageView within the inner-Boundry of a subview

Good day all; 大家好!

Firstly, either a process or pseudo code is hopefully sufficient to my question (obj-c code is very welcomed if you can spare the time and effort). 首先,希望处理或伪代码足以解决我的问题(如果您可以节省时间和精力,欢迎使用obj-c代码)。

I have a UIView the contains many subviews that represent a path to travel along. 我有一个UIView,其中包含许多子视图,这些子视图代表前进的路径。 These subviews (notionally) have a border and hence an inner boundary in which a sprite's movement is limited to. 这些子视图(在概念上)具有边界,因此具有子画面的运动仅限于其中的内部边界。 The subviews are linked together (no border between the linkages) and so crossing from one subview to the other is required. 子视图链接在一起(链接之间没有边界),因此需要从一个子视图跨越到另一个子视图。

I have implemented an ImageView to represent the sprite and is attached to the main UIView as is the subviews. 我已经实现了一个ImageView来表示精灵,并像子视图一样附加到主UIView上。

Now, what I have done is implement the event handling and workout where the finger movements are and try to move the sprite within the confines of the subviews manually. 现在,我要做的是在手指移动的地方实现事件处理和锻炼,并尝试在子视图范围内手动移动精灵。

Is there a better approach as I have noticed that you can set boundaries on views and so on. 有没有一种更好的方法,如我所注意到的,您可以设置视图等的边界。 Is there a way to allow the iPhone to manage where the sprite is allowed to move within a subview or do I have to manually compute movement limitations within a subview and then limit movement manually on the sprite. 有没有一种方法可以让iPhone管理子视图允许在子视图中移动的位置,或者我必须手动计算子视图内的运动限制,然后手动限制子视图上的运动。

"Bounds" is not a boundary, but the definition of the size of the view. “边界”不是边界,而是视图大小的定义。 You can't really have the view do anything, except turn on clipping which would stop the sprite from being drawn outside the view. 您实际上不能使视图执行任何操作,除了打开剪辑会阻止精灵在视图外部绘制。

Are you sure you don't want to use some kind of game engine that would have the ability to help you handle collision checks? 您确定不想使用某种能够帮助您进行碰撞检查的游戏引擎吗?

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

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