Animation Effect of animatewithduration

Source: Internet
Author: User

You are encouraged to use the animatewithduration Method for animation effects in ios4.0 and later versions. Of course, the previous begin/commit method is still used. The following describes how to use animatewithduration in detail.

Function prototype:

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Where,

  • Duration is the animation duration.
  • Animations is the animation effect code block.

The following shows the attributes for setting the animation effect:

  • Frame
  • Bounds
  • Center
  • Transform
  • Alpha
  • Backgroundcolor
  • Contentstretch


    For example, if a view fades out of the screen and another view shows code:

    [UIView animateWithDuration:1.0 animations:^{        firstView.alpha = 0.0;        secondView.alpha = 1.0;}];
    • Completion is the code block that is executed after the animation is executed.
    • Options is the animation execution option. Refer to here
    • Delay is the waiting time before the animation starts to run.

    How to achieve continuous animation?
    You can add animations to the completion code block.
    The following is the instance code:

    [UIView animateWithDuration:2.0                 animations:^{                     oldImageView.alpha = 0.0;                     newImageView.alpha = 1.0;                     //imageView.center = CGPointMake(500.0, 512.0);                 }                 completion:^(BOOL finished){                     [UIView animateWithDuration:4.0                                      animations:^{                                          newImageView.center = CGPointMake(500.0, 512.0);                                      }];                 }];

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.