7
\$\begingroup\$

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 are the modern best practices for achieving the same result?

\$\endgroup\$
  • \$\begingroup\$ In the future, please leave a comment on what version of iOS the code comes from and what version of iOS you're looking to upgrade to. Nearly 2 years later, this question-and-answer is purely meaningless because there's no documentation as to what iOS versions we're discussing. \$\endgroup\$ – nhgrif Jun 17 '14 at 0:13
  • \$\begingroup\$ The answer certainly wasn't meaningless for me at the time. The question is still open to someone providing a new answer for even more recent versions of iOS. Thanks for your contribution though, it certainly adds more meaning to this discussion.. \$\endgroup\$ – djskinner Jun 17 '14 at 11:25
  • \$\begingroup\$ At the time, it certainly isn't meaningless, I agree. But without some sort of documentation as to what version of iOS we're talking about, it's problematic. Particularly if/when the current answer becomes irrelevant. Yes, I can return and add an updated answer, but the current answer has the green check mark, and if neither you or the current answerer returns to update that answer or its "Accept" status, that will be the first answer people try, as there's nothing to warn them "Hey, this is for iOS 6 and we're on iOS 11." \$\endgroup\$ – nhgrif Jun 17 '14 at 11:32
10
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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