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?

Nick Udell
5,2471 gold badge29 silver badges68 bronze badges
asked Sep 22, 2012 at 17:15
\$\endgroup\$
3
  • \$\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\$ Commented Jun 17, 2014 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\$ Commented Jun 17, 2014 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\$ Commented Jun 17, 2014 at 11:32

1 Answer 1

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.

answered Sep 23, 2012 at 2:54
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.