UIView Animation too quick

Discussion in 'iOS Programming' started by nashyo, May 19, 2012.

  1. nashyo macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    Hi,

    The following code works great, but the shift is too sudden and it stops suddenly. How can I apply ease to the speed at the beginning at at the end of the animation?

    Code:
    -(void)shiftView:(UIView*)view
    {
        static int deltaX = 300;
        [UIView beginAnimations: @"shift" context: nil];
        view.center = CGPointMake( view.center.x + deltaX, view.center.y);
        [UIView commitAnimations];
    } 
    many thanks in advance
     
  2. ArtOfWarfare, May 19, 2012
    Last edited: May 19, 2012

    ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Why not use an animation block with options EaseIn and EaseOut set?

    Edit: The method is this -

    Code:
    animateWithDuration:delay:options:animations:completion:
    Changing your code to use it, it would look like this:

    Code:
    -(void)shiftView:(UIView*)view
    {
        [UIView animateWithDuration: 0.5 [i]//how many seconds it should run for, as a float. Change as necessary.[/i]
         delay: 0.0 [i]// unless you do want a delay before the animation starts.[/i]
         options: UIViewAnimationOptionCurveEaseInOut [i]// Flag that says it shouldn't abruptly start or end.
         animations:^{ [i] // Define what the end of the animation should look like between these brackets.[/i]
          static int deltaX = 300;
          view.center = CGPointMake( view.center.x + deltaX, view.center.y); }
         completion: NULL [i] // You could have a block here of everything that should happen right when the animation finishes.[/i]
    }
     

Share This Page