objective c - Locating the nearest open space within a UIView -
i have uiview user can add subviews to. need application automatically place subview user @ first found open location.
a location considered open if frame of subview placed not intersect other subviews.
the calculation locate open area not need instant - run when user first enters scene, @ point saves location if user placed it.
the container uiview large enough have open space place subview (there limited number of subviews user can add).
what simplest way determine location place subview?
i posted description of algorithm commonly used solve these sorts of problems in answer question: finding largest rectangle in 2d array. it's easy adapt solution problem. in question filled spaces on grid, made determining amount advance scan line little easier, have more careful. other question looking empty rectangle maximal area, can exit algorithm find first fit.
of course, if subviews same size, solutions identical.
hope helps.
Comments
Post a Comment