Animation effects of iphone with Animation

Source: Internet
Author: User

1. I wrote a small Demo to implement up and down movement:

 

The main code is as follows:

-(IBAction) upChange :( id) sender {

If (typeView = down ){

[Self. downBtn setHidden: NO];

[Self. upBtn setHidden: NO];

[UIView animateWithDuration: 0.5 animations: ^ {

Self. upView. center = CGPointMake (self. upView. center. x, 0 );

Self. downView. center = CGPointMake (self. downView. center. x, (self. upView. frame. size. height + self. downView. frame. size. height)/2 );

}];

TypeView = middle;

} Else if (typeView = middle ){

[Self. downBtn setHidden: NO];

[Self. upBtn setHidden: YES];

[UIView animateWithDuration: 0.5 animations: ^ {

Self. upView. center = CGPointMake (self. upView. center. x,-(self. upView. frame. size. height/2 ));

Self. downView. center = CGPointMake (self. downView. center. x, self. downView. frame. size. height/2 );

}];

TypeView = up;

}

}

-(IBAction) downChange :( id) sender {

If (typeView = middle ){

[Self. downBtn setHidden: YES];

[Self. upBtn setHidden: NO];

[UIView animateWithDuration: 0.5 animations: ^ {

Self. upView. center = CGPointMake (self. upView. center. x, self. upView. frame. size. height/2 );

Self. downView. center = CGPointMake (self. downView. center. x, self. upView. frame. size. height + self. downView. frame. size. height/2 );

}];

TypeView = down;

} Else if (typeView = up)

{

[Self. downBtn setHidden: NO];

[Self. upBtn setHidden: NO];

[UIView animateWithDuration: 0.5 animations: ^ {

Self. upView. center = CGPointMake (self. upView. center. x, 0 );

Self. downView. center = CGPointMake (self. downView. center. x, (self. upView. frame. size. height + self. downView. frame. size. height)/2 );

}];

TypeView = middle;

}

}

This is the main code, and there are also some small details that need attention. For example, you need to calculate the exact location of the two views.

The following describes how to use the [UIView animateWithDuration] method:

Function prototype:

+ (Void) animateWithDuration :( NSTimeInterval) duration animations :( void (^) (void) animations _ notify (_ MAC_NA, __iphone_4_0); // delay = 0.0, options = 0, completion = NULL

Duration: animation duration

Animations: This code block defines all attributes of the animation to be completed for all views;

There are two other functions:

+ (Void) animateWithDuration :( NSTimeInterval) duration delay :( NSTimeInterval) delay options :( UIViewAnimationOptions) options animations :( void (^) (void) animations completion :( void (^) (BOOL finished) completion _ OSX_AVAILABLE_STARTING (_ MAC_NA ,__ IPHONE_4_0 );

+ (Void) animateWithDuration :( NSTimeInterval) duration animations :( void (^) (void) animations completion :( void (^) (BOOL finished) completion _ signature (_ MAC_NA, __iphone_4_0); // delay = 0.0, options = 0

Options: Specifies the animation execution option.

Completion: the code block to be executed after the animation is completed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.