iphone - iOS Drawing a grid view for dragging/dropping objects that snap to that grid -


i working on project requires custom view segmented squares. need able drag view on , when drop object snap grid squares. need able iterate on every square in grid , determine if object inside particular grid square.

i realize bit of general question i'm looking direction on start, classes or frameworks might exist reference. direction @ appreciated. thanks.

question #1: user needs able drag view on , when drop object snap grid squares.

lets dragging uiview. on touchesended of uiview use center property contains x , y coordinate center values of uiview , pass function tests see grid square inside of.

this (assume uiview name draggingview):

for (cgrect gridsquare in gridarray) {     if (cgrectcontainspoint(gridrect, draggingview.center)) {         // return gridsquare contains object     } } 

now in case wondering gridarray is, array of grid squares make game board. if need creating let me know.

question #2: user needs able iterate on every square in grid , determine if object inside particular grid square.

if able follow along above quite easy. while iterating on grid squares use gridsquare origin values see if of draggingview subviews have same origin. using can return uiview inside particular square. see below:

- (uiview *)findviewinsquare {     (cgrect rect in gridarray) {         (uiview *view in [self.view subviews]) {             if (cgpointequaltopoint(view.frame.origin, rect.origin)) {                 return view;   // returns view in grid square             }         }     }     return nil; } 

hopefully makes sense, , let me know if need clarification.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -