Animation effect: Animation_html/css_WEB-ITnose

Source: Internet
Author: User
Animation effect: Animation first creates an image imageView
 self.imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tara4.jpg"]];    self.imageView.frame =CGRectMake(85, 400, 200, 200);    self.imageView.layer.cornerRadius =100;    self.imageView.layer.masksToBounds=YES;    [self.view addSubview:self.imageView];
Write several button clicking methods in the button clicking method. Click the trigger effect. 1. animation provided by UIView (1). // The first animation provided by UIView
// Duration animation interval (double type) [UIView animateWithDuration: 3 animations: ^ {// write the animation content in the block self. imageView. frame = CGRectMake (100,100,100, 75) ;}]; move the imageView to the new location and change the size to the new
(2) The second type of UIView moves the imageView to a new location, changes the size to a new location, and finally returns to the original location.
[UIView animateWithDuration:5 animations:^{         self.imageView.frame =CGRectMake(30, 100, 300, 225);        self.imageView.alpha =0;    } completion:^(BOOL finished) {        [UIView animateWithDuration:3 animations:^{        self.imageView.frame =CGRectMake(85, 400, 200, 150);            self.imageView.alpha =1;        }];    }];
(3) The third method of UIView can repeat the second parameter: latency, and the third parameter: animation type, which only repeats the content of the animation.
[UIView animateWithDuration:5 delay:0.1 options:UIViewAnimationOptionRepeat animations:^{        self.imageView.frame =CGRectMake(30, 100, 300, 225);        self.imageView.alpha =0;    } completion:^(BOOL finished) {        [UIView animateWithDuration:3 animations:^{                    self.imageView.frame =CGRectMake(85, 400, 200, 150);                        self.imageView.alpha =1;                    }];    }];
(4) UIView fourth trembling animation // The third parameter: the smaller the setting, the more intense the vibration. // The fourth parameter: the larger the setting, the higher the initial image speed.
   [UIView animateWithDuration:5 delay:0.1 usingSpringWithDamping:0.1 initialSpringVelocity:10 options:UIViewAnimationOptionRepeat animations:^{        self.imageView.frame =CGRectMake(30, 100, 300, 225);        self.imageView.alpha =0;    } completion:^(BOOL finished) {        [UIView animateWithDuration:3 animations:^{                                self.imageView.frame =CGRectMake(85, 400, 200, 150);                                    self.imageView.alpha =1;                                }];    }];
2. Operate the view through transform (1). Rotate the view
// Second parameter: Set the rotation radians (π/4) self. imageView. transform = CGAffineTransformRotate (self. imageView. transform, M_PI_4 );
(2) scale the view. // The second and third parameters: Set the zoom ratio.
 self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 0.9, 0.9);
(3) set the view offset for the view offset.
    self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, 50, 50);
3. the layer animation layer is mainly responsible for displaying some settings of the control, such as borders and radians. There are many types of layer animation. The UIView animation we see also encapsulates several layer Animations (1 ). create an animation effect
CATransition * transition = [CATransition animation]; set the animation type: cube (), rippleEffect (Water ripple) suckEffect oglFlip transition. type = @ "rippleEffect"; // set the animation duration [transition setDuration: 3]; // set the number of animation repetitions // the maximum value of the NSIntegerMax integer [transition setRepeatCount: NSIntegerMax]; // Add the animation effect to the imageView and add it to the imageView layer [self. imageView. layer addAnimation: transition forKey: @ "transistion"];
(2) layer animation second (zoom in and out)
CABasicAnimation * basic = [CABasicAnimation animationWithKeyPath: @ "transform. scale "]; // you need to assign values to the layer animation settings in the kvc mode, that is, you need to specify a key and then set the animation duration [basic setDuration: 3]; // Number of animation executions [basic setRepeatCount: NSIntegerMax]; // This animation sets a scaling effect. You need to give the initial value an initial multiple of basic. fromValue = [NSNumber numberWithInt: 1]; // set the ending multiple of the scaling of an ending value to basic. toValue = [NSNumber numberWithInt: 2]; // toValue and fromvalue need an id-type object (integer type is required, 0.5 is calculated as 0) // Add the animation to the view [self. imageView. layer addAnimation: basic forKey: @ "basic"];
(3) rotate the image
CABasicAnimation * basic = [CABasicAnimation animationWithKeyPath: @ "transform. rotation "]; // set the angle to basic. fromValue = [NSNumber numberWithInt: 0.0]; basic. toValue = [NSNumber numberWithFloat:-4 * M_PI_2]; // set the animation duration [basic setDuration: 3]; // Times [basic setRepeatCount: NSIntegerMax]; [self. imageView. layer addAnimation: basic forKey: @ "basic"]; // whether to return to the original [basic setAutoreverses: YES];
(4). Key Frame Animation
CAKeyframeAnimation * keyAnimation = [CAKeyframeAnimation animationWithKeyPath: @ "position"]; // create a walking path for the animation to record the moving key coordinate CGMutablePathRef path = CGPathCreateMutable (); // specify the starting Coordinate Position // The first parameter: Use path to save the starting path // The second parameter: NULL // The third four parameters: the starting coordinate CGPathMoveToPoint (path, NULL, self. imageView. frame. origin. x, self. imageView. frame. origin. y); // set the image's mobile track CGPathAddLineToPoint (path, NULL, 100,100); CGPathAddLineToPoint (path, NULL, 300, 20); CGPathAddLineToPoint (path, NULL, 50, 10); CGPathAddLineToPoint (path, NULL, 140,200); // set a curve path CGPathAddCurveToPoint (path, NULL, 200,200,200,100,120, 40) for the view; CGPathAddCurveToPoint (path, NULL, 80, 10, 20,100,300,100); CGPathAddCurveToPoint (path, NULL, 20, 90, 20,100,200,150); CGPathAddCurveToPoint (path, NULL, 30, 70, 60, 90,110, 50 ); // set the animation duration [keyAnimation setDuration: 3]; [keyAnimation setRepeatCount: NSIntegerMax]; // place the designed route in the animation [keyAnimation setPath: path]; // Add the animation to the view [self. imageView. layer addAnimation: keyAnimation forKey: @ "keyAnimation"];

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.