title: iOS - animating UIView on iPad, change x origin and width simultaneously?
body: <p>I'm having some trouble with UIView animations on iPad.</p>
  
  <p>I'm working on a project in which I have implemented a "facebook style" menu on the left, using the <a href="https://github.com/mystcolor/JTRevealSidebarDemo" rel="nofollow noreferrer">JTRevealSidebar framework</a>.</p>
  
  <p>This framework works perfectly, however, instead of "pushing" the right side view off the screen, I would like to resize it, so the user can still see the whole content of the right-side view.</p>
  
  <p>I have managed to do this by changing the view's frame as well as doing the offset.</p>
  
  <p>This is what it looks like with the sidebar open:</p>
  
  <p><img src="https://i.stack.imgur.com/3qotF.png" alt="enter image description here"></p>
  
  <p>And when it's closed:</p>
  
  <p><img src="https://i.stack.imgur.com/3aKcd.png" alt="enter image description here"></p>
  
  <p>This right-side view contains a navigation bar with two buttons (one button on the left to toggle the left sidebar, and another button on the right to dismiss the controller), and the content itself is a simple UIWebView.</p>
  
  <p>The problem I am facing is during the animation (from the full-screen state to the sidebar open state):</p>
  
  <p>When I change the view's frame, even after doing the translate, the view resizes before the animation starts, which gives a weird effect like this:</p>
  
  <p><img src="https://i.stack.imgur.com/H6YeM.png" alt="enter image description here"></p>
  
  <p>I would like to keep the right side of the webview anchored to the right side of the screen and only have the left side change position when animating (basicaly so that the "done" button is always in the same position).</p>
  
  <p>Here is the animation code:</p>
  
  <pre><code>- (void)revealSidebar:(BOOL)shouldReveal {
  
      if (shouldReveal) {
  
          [UIView beginAnimations:@"" context:nil];
          [UIView setAnimationDuration:0.3];
  
          // Push the view to the right
          contentView.transform = CGAffineTransformTranslate(contentView.transform, CGRectGetWidth(sidebarView.frame), 0);
  
          // Resize the view so it fits on remaining part of the screen
          contentView.frame = CGRectMake(contentView.frame.origin.x, contentView.frame.origin.y, contentView.frame.size.width-sidebarView.frame.size.width, contentView.frame.size.height);
  
  
          // The problem is here: the view's frame is changed before the
          // Translate transformation actualy starts...
          //
          // Is there a way to change the x origin and the width simultaneously ?
  
          [UIView commitAnimations];
  
  
      } else {
          [UIView beginAnimations:@"" context:nil];
          [UIView setAnimationDuration:0.3];
  
          // Reset the frame so that it takes up whole screen
          contentView.frame = CGRectMake(contentView.bounds.origin.x,contentView.bounds.origin.y,contentView.frame.size.width+sidebarView.frame.size.width,contentView.frame.size.height);
  
          [UIView commitAnimations];
      }
  
      _state.isShowing = shouldReveal ? 1 : 0;
  }
  </code></pre>
  
  <p>I've had no luck so far, and was wandering if anyone had any ideas as to how I could achieve this.</p>
  
  <p>Thank you</p>