title: how to make smooth UIView splitting animation?
body: <p>Hi i am trying to implement split the <code>UIView</code> using <code>UIPinchGestureRecognizer</code>, but the following issue are their, if any one know how to solve kindly.</p>
  
  <ol>
  <li><p>This is my pinchGestureHandlerCode:</p>
  
  <pre><code>- (IBAction)splitView:(UIPinchGestureRecognizer*)recognizer
  {
      if(recognizer.state == UIGestureRecognizerStateBegan)
      {
          CGPoint selectedFolderPoint = CGPointMake([recognizer locationInView:recognizer.view].x,
                                            recognizer.view.frame.origin.y);
          self.splitPosition = ([recognizer locationOfTouch:0 inView:recognizer.view].x +
                        [recognizer locationOfTouch:1 inView:recognizer.view].x)/2;
  
  
      //STEP 1: Capture the Main View Content into an image
      [self captureImageFromPointAndSetupMaskView:selectedFolderPoint];
  }
  else if(recognizer.state == UIGestureRecognizerStateChanged)
  {
       CGPoint selectedFolderPoint = CGPointMake(recognizer.scale,
                                            recognizer.view.frame.origin.y);
  
      //STEP 2: Reduce the left image width, and move the right image origin according to the finger move of user.
      [self layoutBottomPartOfMainViewRelativeToPointInMainView:selectedFolderPoint];
  
  
      [UIView beginAnimations:@"split" context:NULL];
      [UIView setAnimationDuration:0.1];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
      //captures the main background view's image
  
      //STEP 3- Push The Layer-3 which hosts the other part of the Main Content View
      [UIView commitAnimations];
  
  }
  else if(recognizer.state == UIGestureRecognizerStateEnded)
  {
      // STEP 3: remove the both image view from the view.
      [self layoutFinalFrameOfBottomPartOfMainContentView];
      [UIView commitAnimations];
  }
  </code></pre>
  
  <p>}</p></li>
  </ol>
  
  <p>STEMP 1 METHOD:</p>
  
  <pre><code>-(void)captureImageFromPointAndSetupMaskView:(CGPoint)selectedFolderPoint
  {
      UIGraphicsBeginImageContext(self.superview.frame.size);
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
  
      CGImageRef leftTempRef = backgroundImage.CGImage;
      CGImageRef leftImageRef = CGImageCreateWithImageInRect(leftTempRef, 
  </code></pre>
  
  <p>CGRectMake(self.bounds.origin.x,
  self.bounds.origin.y,                                                                                 selectedFolderPoint.x,
  self.bounds.size.height));</p>
  
  <pre><code>    UIImage *leftImage = [UIImage imageWithCGImage:leftImageRef];
  
      leftImageBackgroundView = [[UIImageView alloc] initWithImage:leftImage];
      [self.leftBackgroundView addSubview:leftImageBackgroundView];
  
      CGImageRef rightTempRef = backgroundImage.CGImage;
      CGImageRef rightImageRef = CGImageCreateWithImageInRect(rightTempRef, 
  </code></pre>
  
  <p>CGRectMake(selectedFolderPoint.x,
  self.bounds.origin.y,                                                                       self.superview.bounds.size.width,                                                                       self.bounds.size.height));</p>
  
  <pre><code>    UIImage *rightImage = [UIImage imageWithCGImage:rightImageRef];
  
      rightImageBackgroundView = [[UIImageView alloc] initWithImage:rightImage];
      [self.rightBackgroundView addSubview:rightImageBackgroundView];
  
  
  
      [self.leftBackgroundView setFrame:CGRectMake(self.bounds.origin.x,
                                               self.bounds.origin.y,
                                               selectedFolderPoint.x,
                                               self.frame.size.height)];
  
      [self.rightBackgroundView setFrame:CGRectMake(selectedFolderPoint.x,
                                                self.bounds.origin.y,
                                                self.superview.bounds.size.width,
                                                self.bounds.size.height)];
  }
  </code></pre>
  
  <p>STEP 2 METHOD:</p>
  
  <pre><code>-(void)layoutBottomPartOfMainViewRelativeToPointInMainView:(CGPoint)selectedFolderPoint
  {
  [self.leftBackgroundView setFrame:CGRectMake(self.leftBackgroundView.bounds.origin.x,
                                               self.leftBackgroundView.bounds.origin.y,
                                               (self.leftBackgroundView.bounds.size.width -
                                                  selectedFolderPoint.x),
                                               self.leftBackgroundView.bounds.size.height)];
  
  [self.rightBackgroundView setFrame:CGRectMake(self.rightBackgroundView.frame.origin.x + selectedFolderPoint.x,
                                                self.rightBackgroundView.bounds.origin.y,
                                                self.rightBackgroundView.bounds.size.width - selectedFolderPoint.x,
                                                self.rightBackgroundView.bounds.size.height)];
  
  if(((ABS(self.leftBackgroundView.bounds.origin.x+self.leftBackgroundView.bounds.size.width)-
       self.rightBackgroundView.bounds.origin.x) &gt; 100) &amp;&amp;
     ((ABS(self.leftBackgroundView.bounds.origin.x+self.leftBackgroundView.bounds.size.width)-
       self.rightBackgroundView.bounds.origin.x) &lt; 110))
  {
      [self switchView];
      NSDictionary *message;
      [self.timelineController sendEvent:SWITCH_VIEW withMessage:message];
      [self layoutFinalFrameOfBottomPartOfMainContentView];
  
  }
  [UIView setAnimationsEnabled:NO];
  [UIView setAnimationsEnabled:YES];
  }
  </code></pre>
  
  <p>STEP 3 METHOD:</p>
  
  <pre><code>-(void)layoutFinalFrameOfBottomPartOfMainContentView
   {
       [self.leftBackgroundView setFrame:CGRectMake(self.bounds.origin.x,
                                               self.leftBackgroundView.bounds.origin.y,
                                               self.bounds.origin.x,
                                                 self.leftBackgroundView.bounds.size.height)];
  
       [self.rightBackgroundView setFrame:CGRectMake(self.bounds.origin.x,
                                                self.rightBackgroundView.bounds.origin.y,
                                                self.bounds.origin.x,
                                                self.rightBackgroundView.bounds.size.height)];
  
      leftImageBackgroundView.image = nil;
      rightImageBackgroundView.image = nil;
  }
  </code></pre>
  
  <p>The issue are:</p>
  
  <ol>
  <li>i am trying to make smooth animation but its running too fast and suddenly moving both side.</li>
  <li>if i to same pinch gesture more number of time app getting crash and showing memory warning.</li>
  </ol>
  
  <p>if any one know what mistake i am doing in my code kindly help me to solve the problem or there is any other way to do the same animation kindly give way to me....</p>
  
  <p>Thanks in advance... ...</p>