0

I am coding an iOS game and I am trying to move down an instance of a Tile (Tile being a subclass of UIImageView.)

Precisely, what I want is having my instance of Tile moving from point A(x,y) to point B(x,y+70) in 0.20s.

I already read that post, that describes a similar problem: change position of the UIImageView

I used the recommended code and adapted it to my case. So here is the code of the method I use:

- (void) moveTileDown {
    [UIView animateWithDuration:0.20
                          delay:1.0
                        options: UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y + 70, self.frame.size.width, self.frame.size.height);
                     }
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];
}

But now, here is my problem. Instead of going from A(x,y) to B(x,y+70), when the method is called, my tile Jumps to C(x,y-70) and comes back to A in 0.20s.

In order to give more info, the moveTileDown method is called from a for loop that takes place in another controller

        for (int i=0; i <firstTileRow; i++){
            [[[_lines objectAtIndex:i] objectAtIndex:firstTileColumn] moveTileDown];
            [[[_lines objectAtIndex:i] objectAtIndex:secondTileColumn] moveTileDown];
        }

Any idea?

Community
  • 1
  • 1
Olivier_d
  • 46
  • 4
  • Replace this option `UIViewAnimationOptionBeginFromCurrentState` with `UIViewAnimationOptionCurveEaseIn`. – iphonic Oct 30 '14 at 17:25
  • @iphonic ok, updated :) (but that does not change the problem) – Olivier_d Oct 30 '14 at 17:31
  • Now the question is when do you call the function `moveTileDown` ? can you update the full implementation? – iphonic Oct 30 '14 at 17:33
  • @iphonic I added more details, and updated the description of my problem. Actualy, the tile does not come back from B to A, it jumps to C and comes back to A. The motion is the right one and in the right direction, but it does not start from the initial position of the tile. – Olivier_d Oct 30 '14 at 18:04
  • Can you put `NSLog(@"Initial Frame: %@",NSStringFromCGRect(self.frame));` at the first line of `moveTileDown ` function before the animation block and see the log.. – iphonic Oct 30 '14 at 18:19
  • @iphonic actually I found the pb. It's due to auto layout. I just unchecked "use auto layout" box on interface builder and I got the expected behaviour. I think I need to learn more about how auto layout works. – Olivier_d Oct 30 '14 at 21:48

0 Answers0