Q:

Overlap and Swapping Images in iOS

I want to swap two images. When I move the drag image and it overlaps 50% or greater on any other image in the view it must be swapped. The problem is how can I check the drag image is 50% or more than 50% overlap with the other image. Please help and suggest the logic with a code example. 
The code I am trying is : 
if (imgVw.tag != self.tag) { 
     CGRect imgVwRect = CGRectMake(imgVw.frame.origin.x +(imgVw.frame.size.width/2), imgVw.frame.origin.y+(imgVw.frame.size.height/2), imgVw.frame.size.width, imgVw.frame.size.height);

     CGRect movingImgRect = CGRectMake(newCenter.x+self.frame.size.width, newCenter.y+self.frame.size.height, self.frame.size.width, self.frame.size.height);

    if (movingImgRect.origin.x >= imgVwRect.origin.x && movingImgRect.origin.y >= imgVwRect.origin.y)
    {

         NSLog(@"img view tag %lu",imgVw.tag);
         UIImage *tempImg = self.image;
         [self setImage:imgVw.image];
         [imgVw setImage:tempImg];                  
     }

}

A:

This is pretty straightforward.
Use the method CGRectIntersection to calculate the intersection of the 2 rects.
Then compare the area of the intersection with the area of the moving rect. Something like this (assuming I understand your code
if (imgVw.tag != self.tag) 
{ 
  CGRect imgVwRect = CGRectMake(imgVw.frame.origin.x +(imgVw.frame.size.width/2),
    imgVw.frame.origin.y+(imgVw.frame.size.height/2), 
    imgVw.frame.size.width, 
    imgVw.frame.size.height);

  CGRect movingImgRect = CGRectMake(newCenter.x+self.frame.size.width,
    newCenter.y+self.frame.size.height, 
    self.frame.size.width, 
    self.frame.size.height);

  //Figure out the intersection rect of the 2 rectangles
  CGRect intersectionRect = CGRectIntersection(imgVwRect, movingImgRect);

  //Find the area of the intersection
  CGFloat xArea = intersectionRect.size.height * intersectionRect.size.width;

  //Find the area of the moving image 
  //(this code could be done once and saved in an iVar)
  CGFloat movingImgArea = movingImgRect.size.height * movingImgRect.size.width;

  //Is the intersection >= 1/2 the size of the moving image?
  if (xArea*2 >= movingImgArea)
  {
    //Do whatever you need to do when the 2 images overlap by >= 50%
  }
}

