What are block animation methods in iPhone OS 4.0?

I am trying to implement a game using the SDK for iPhone OS 4.0 (iOS4?). In previous versions of the SDK, I used [UIView beginAnimations: context:] and [UIView commitAnimations] to create some animations. However, when I look at the function documentation in 4.0, I see this comment.

Using this method is not recommended for iPhone OS 4.0 and later. You should use block-based animation methods instead.

You can find it here: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/commitAnimations

My question is, what is block animation in iPhone OS 4.0? Although I used the beginAnimations: context: and commitAnimations functions to create animation blocks.

+55
iphone ios4 core-animation uiview
Jun 27 '10 at 8:32
source share
3 answers

If you follow this link and scroll through the list a bit, you'll see new iimate methods for animating.

animateWithDuration:animations: animateWithDuration:animations:completion: animateWithDuration:delay:options:animations:completion: 

There are also some related transition methods. For each of them, the animation argument is a block object :

animation
A block object containing changes to commit to views. Here you programmatically change any animated properties of the views in the hierarchy of your presentation. This block takes no parameters and has no return value. This parameter must not be NULL.

Block objects are part of concurrent programming.

+42
Jun 27 '10 at 8:51
source share

I posted an example on the blog :

  CGPoint originalCenter = icon.center; [UIView animateWithDuration:2.0 animations:^{ CGPoint center = icon.center; center.y += 60; icon.center = center; } completion:^(BOOL finished){ [UIView animateWithDuration:2.0 animations:^{ icon.center = originalCenter; } completion:^(BOOL finished){ ; }]; }]; 

The above code will animate the UIImageView * (icon) in a 2 second animation. After its completion, another animation will move the icon back to its original position.

+118
Jul 23 '10 at 7:08
source share

Here is a very simple example. The code simply fades the UIView and hides it after the animation finishes:

 [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^ { bgDisplay.alpha = 0.0; } completion:^(BOOL finished) { bgDisplay.hidden = YES; }]; 

or in other formatting:

 [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^ { bgDisplay.alpha = 0.0; } completion:^(BOOL finished) { bgDisplay.hidden = YES; }]; 
+20
Nov 15 '11 at 11:05
source share



All Articles