As others have said, you're question is too broad.
I would however suggest subclassing UIView and using a UIPanGestureRecognizer to detect a grab, then move the views.
When the view is released call a function to check that objects location with respect to the other views and swap views accordingly with animations. If the view is within a certain range of it's origin it simply snaps back with an animation.
Your UIView subclass could look something like this:
@interface DraggableView () <UIGestureRecognizerDelegate>
@property (nonatomic) float originX;
@end
@implementation DraggableView
-(id)initWithFrame:(CGRect)frame {
self = [self initWithFrame:frame];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(Touched:)];
[pan setMinimumNumberOfTouches:1];[pan setMaximumNumberOfTouches:1];
[pan setDelegate:self];
[self addGestureRecognizer:pan];
return self;
}
- (void) Touched:(id)sender {
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.superview];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
self.originX = [[sender view] center].x;
}
else {
translatedPoint = CGPointMake(self.originX+translatedPoint.x, self.center.y);
[[sender view] setCenter:translatedPoint];
}
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded)
{
// Check if view should swap or bounce back
}
}