Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

ios4 - What are block-based animation methods in iPhone OS 4.0?

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

Use of this method is discouraged in iPhone OS 4.0 and later. You should use the 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 are block-based animations in iPhone OS 4.0? I though that the beginAnimations:context: and commitAnimations functions were used to create animation blocks..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have posted an example in my 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 a UIImageView* (icon) in a 2-second animation. Once completed, another animation will move the icon back to it’s original position.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...