Reputation: 8636
I would like to find out in row and column ordered UIViews, subviews inside a superview, while dragging one of them and then let it go with which one of all the others intersects its bigger area.
I need this to insert the draggable UIView between the UIViews that intersects.
Do I have to calculate frame.origin values? If yes could I have an example? Or this could happen using iOS SDK ?
I already aware of CGRectIntersectsRect but this gives me the first UIView that intersects. Though its most possible need to place the UIView between other UIViews. I had an example using pointInside with no luck.
Code:
CGPoint centerInView = [viewDragged convertPoint:viewDragged.center toView:view]; // Checking with the views inside NSMutableArray in a for in statement
if ([view pointInside:centerInView withEvent:nil]) // This if statement almost never is true sometimes only
Other approach:
if (CGRectIntersectsRect(viewDragged.frame, view.frame)) // This always happens for the first UIView in subviews that intersects. Not so applicable for information
Basically the idea is to insert the draggable view between the nearest UIViews.
Imagine 1,2,3,4,5 same size views in the screen and try to drag the first let it go between 4,5 and then have 2,3,4,1,5. You get the idea. This all should happen without the help of any new Grid. The only part I need is calculate that you put the 1 UIView between 4,5.
I could start calculating frames,origins but this does not sound efficient to me. Any thoughts?
Thank you.
Upvotes: 0
Views: 263
Reputation: 286
I now it's an old question, but this might help. The view with the biggest CGRect Intersection gets 'selected'.
CGRect intersect = CGRectZero;
UIView *selectedDropView = nil;
for (UIView *dropView in dropViews) {
CGRect intersectTmp = (CGRectIntersection(self.frame, dropView.frame));
if (intersectTmp.size.width * intersectTmp.size.height > intersect.size.width * intersect.size.height) {
intersect = intersectTmp;
selectedDropView = dropView;
}
}
Upvotes: 1