简体   繁体   中英

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).

I have a UIView the contains many subviews that represent a path to travel along. 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.

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.

"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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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