开发者

What's the best way to do this (iPhone SDK UI question)

开发者 https://www.devze.com 2023-01-23 01:56 出处:网络
Here\'s what I need to do: I will have a toolbar with multiple objects on it (f开发者_开发知识库or this we\'ll call them A,B,C,D) and I want to be able to have the user click and drag them around and

Here's what I need to do:

I will have a toolbar with multiple objects on it (f开发者_开发知识库or this we'll call them A,B,C,D) and I want to be able to have the user click and drag them around and be able to snap them to a grid and connect to each other.

Sounds easy, right? Well here's my problem: some objects are different sizes, so A could be a 1x1, B be 1x3, C be 3x4, etc.

So how should I do this? I was thinking about just having each element as a separate UIImageView (or UIView, haven't decided yet) that can be dragged around, then take it's location and see what images are next to it.

Another thing is I have to be able to export these locations to either xml or json (not sure yet, probably xml)


It sounds like you would need a subclass of UIView with tessellation or some sort of underlying grid coordinate system with the units being 1x1. The 'tiles' could be subclassed from UIView, having a UIImage and grid position information. If adjacent tiles are by definition connected, then you wouldn't need additional state information about connectedness. And writing this out would be as easy as writing out origins.

I am working on something similar, but with single-sized tiles. It has been fun - especially the insertion logic: positioning a tile between two other tiles and figuring out what gets moved to make room.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号