Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After struggling a lot, finally i achieved the desired result with this algorithm.</p> <ul> <li><p>I calculate the list of overlapping <code>UIImageView's</code> and store it in an array. I am using <code>CGRectIntersectsRect</code> for this. </p> <p>Note : This will also include the <code>UIImageView</code> on which the gesture was applied (say target ImageView). </p></li> <li><p>For each of these overlapping UIImageView, i perform the following steps : </p> <p>1) Calculate the angle between the overlapping ImageView and target ImageView. This will give me the direction to shift the Overlapping ImageView.</p> <p>2) Now shift the overlapping ImageView by some constant distance(say len), such that it maintains the same angle. Direction should be such that it moves away from the target ImageView.</p> <p>3) You can calculate the new x,y co-ordinates using Sin/Cos functions.</p> <p>x = start_x + len * cos(angle);<br> y = start_y + len * sin(angle);</p> <p>NOTE: For ImageViews whose center is less than your target ImageView's center, you will need to subtract the value.</p> <p>4) Now shift the overlapping ImageView to the new calculated center.</p> <p>5) Continue shifting it until the views do not intersect any more.</p></li> <li><p>I am attaching my code. I hope it helps. </p> <blockquote> <p>-(void)moveImage:(UIImageView *)viewToMove fromView:(UIImageView *)imageToSendBack<br> {</p> <pre><code> CGFloat angle = angleBetweenLines(viewToMove.center, imageToSendBack.center); CGFloat extraSpace = 50; CGRect oldBounds = viewToMove.bounds; CGPoint oldCenter = viewToMove.center; CGPoint shiftedCenter; while(CGRectIntersectsRect(viewToMove.frame,imageToSendBack.frame)) { CGPoint startPoint = viewToMove.center; shiftedCenter.x = startPoint.x - (extraSpace * cos(angle)); if(imageToSendBack.center.y &lt; viewToMove.center.y) shiftedCenter.y = startPoint.y + extraSpace * sin(angle); else shiftedCenter.y = startPoint.y - extraSpace * sin(angle); viewToMove.center = shiftedCenter; } viewToMove.bounds = oldBounds; viewToMove.center = oldCenter; [self moveImageAnimationBegin:viewToMove toNewCenter:shiftedCenter]; } </code></pre> </blockquote></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload