title: Why is my UIView animation working differently?
body: <p>I'm working on <a href="https://github.com/MosheBerman/MBTileParser" rel="nofollow">a game engine</a>, and I've run into a rather baffling behavior. I'm sure it's rather simple, but I'd like to figure it out before progressing.</p>
  
  <p>I've subclassed <code>UIImageView</code> and added support for multiple animated sprites. I have controls working too, but I've been seeing a weird behavior. When my character walks up or left, the animation skips a frame, and appears to move faster. Moving right or down goes slower and displays the correct three frames.</p>
  
  <p>I've gone through my whole call stack, and I can't figure it out. Here's what happens:</p>
  
  <ul>
  <li>The user taps on the virtual joypad.</li>
  <li>The game controller view controller dispatches a notification.</li>
  <li>The main player sprite picks up on the notification.</li>
  <li>The sprite asks the delegate if it's allowed to move where it wants to.</li>
  <li>The sprite moves in a given distance if it is indeed allowed to.</li>
  </ul>
  
  <p>The sprite movement code looks like this:</p>
  
  <pre><code>//  Move in a direction
  - (void)moveInDirection:(MBSpriteMovementDirection)direction distanceInTiles:(NSInteger)distanceInTiles withCompletion:(void (^)())completion{
  
  CGRect oldFrame = [self frame];
  CGSize tileDimensions = CGSizeZero;
  
  tileDimensions = [[self movementDataSource] tileSizeInPoints];
  
  if (tileDimensions.height == 0 &amp;&amp; tileDimensions.width == 0) {
  
      NSLog(@"The tile dimensions for the movement method are zero. Did you forget to set a data source?\nI can't do anything with this steaming pile of variables. I'm outta here!");
  
      return;
  }
  
  CGPoint tileCoordinates = CGPointMake(oldFrame.origin.x/tileDimensions.width, oldFrame.origin.y/tileDimensions.height);
  
  //  Calculate the new position
  if (direction == MBSpriteMovementDirectionLeft || direction == MBSpriteMovementDirectionRight) {
      oldFrame.origin.x += (tileDimensions.width * distanceInTiles);
      tileCoordinates.x += distanceInTiles;
  }else{
      oldFrame.origin.y += (tileDimensions.height * distanceInTiles);
      tileCoordinates.y += distanceInTiles;
  }
  
  if (![[self movementDelegate] sprite:self canMoveToCoordinates:tileCoordinates]) {
      [self resetMovementState];
      if(completion){
          completion();
      }
      return;
  }
  
  [self startAnimating];
  
  [UIView animateWithDuration:distanceInTiles*[self movementTimeScaleFactor] delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{
  
      [self setFrame:oldFrame];
  }
                   completion:^(BOOL finished) {
                       //  Perform whatever the callback warrants
                       if(completion){
                           completion();
                       }
                       [self resetMovementState];
                   }];
  }
  </code></pre>
  
  <p>If the <code>MBSpriteMovement</code> direction (which is a typedef of <code>NSUInteger</code>) is up or left, <code>distanceInTiles</code> is a negative integer. The correct distance is calculated, but for some reason, the down and right seem slower. I'm certain it does skip a frame when moving up/left.</p>
  
  <p>Any idea why?</p>
  
  <p>(This is an open source project, and can be found <a href="https://github.com/MosheBerman/MBTileParser" rel="nofollow">here, on GitHub</a>.)</p>