Using animation to achieve the iphone animation effect

Source: Internet
Author: User

1, wrote a small demo, to achieve the effect of moving up and down:

 

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 some small notes that need to be noted, such as the size of your two view, and you need to calculate the exact position.

Let's start with the [UIView Animatewithduration] Method:

Function Prototypes:

+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void) Animations __osx_available_ Starting (__MAC_NA,__IPHONE_4_0); Delay = 0.0, options = 0, completion = NULL

Duration: Animation duration

Animations: The code block is the definition of all the attributes of all the animations that the view wants to complete;

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__osx_available_starting (__MAC_NA,__IPHONE_4_0);//delay = 0.0, options = 0

Options: is an animation execution option

Completion: Is the code block that you want to execute after the animation completes.

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.