Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
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
 
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]
}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.