Animation effects on 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: [cpp]-(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 = midd Le) {[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;}-(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, such as the size of your two views, the exact location must be calculated. The following describes how to use the [UIView animateWithDuration] method: function prototype: + (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 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 :( UIViewAnimation Options) 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: it is the animation execution option completion: it is to be executed after the animation is completed Line of code.

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.