Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I understand that this animation code is outdated:

    [UIView beginAnimations:@"Move" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDelay:0.08];
    self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];

What is the latest and greatest way to achieve the same result in iOS?

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

up vote 6 down vote accepted

In iOS 4 and later you are encouraged to use animation blocks.

[UIView animateWithDuration: 0.5f
            delay: 0.08f
            options: UIViewAnimationCurveEaseIn
            animations: ^{
                self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            }
            completion: ^(BOOL finished){
               // any code you want to be executed upon animation completion
            }
];

One advantage of using block-based animation is that

When this code executes, the specified animations are started immediately on another thread so as to avoid blocking the current thread or your application’s main thread.

This means that the rest of your application will not be "locked up" while your animation is executing.

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.