Animation Group (petals) falling with curves

Source: Internet
Author: User

/*

Caanimationgroup Animation Group

1. An array of animations animations

2, the BeginTime start time

3, the animation group set the "duration (duration)", may cause animation group inside the "animation duration" Invalid

*/

#import "ViewController.h"

@interface Viewcontroller ()

{

Calayer *petal;

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

[Self addbgview];

[Self addanimationgroup];

[Self addpetallayer];

}

#pragma mark-Add a background map

-(void) Addbgview {

Uiimageview *bgview = [[Uiimageview alloc] initWithFrame:self.view.frame];

Bgview.image = [UIImage imagenamed:@ "deciduous. jpg"];

[Self.view Addsubview:bgview];

[Self addpetallayer];

}

#pragma mark-Add a picture to animate

-(void) Addpetallayer {

UIImage *image = [UIImage imagenamed:@ "petal.jpg"];

Petal = [[Calayer alloc] init];

Petal.position = Cgpointmake (100, 200);

Petal.bounds = CGRectMake (0, 0, image.size.width, image.size.height);

Petal.contents = (ID) image. Cgimage;

[Self.view.layer Addsublayer:petal];

}

#pragma mark-Rotate animation ("Base animation")

-(Cabasicanimation *) rotationanimation {

Cabasicanimation *rotation = [cabasicanimation animationwithkeypath:@ "Transform.rotation.z"]; Rotate Z Axis

Rotation.tovalue = @ (m_pi_2*3); Rotation angle

Rotation.removedoncompletion = NO;

return rotation;

}

#pragma mark-The Falling animation

-(Cakeyframeanimation *) dropanimation {

Cakeyframeanimation *drop = [cakeyframeanimation animationwithkeypath:@ "position"];

Cgpathref pathref = cgpathcreatemutable ();

Cgpathmovetopoint (Pathref, NULL, petal.position.x, PETAL.POSITION.Y);

Cgpathaddcurvetopoint cp1x y cpx y set two points draw a curve between these two points

X y termination Point

Cgpoint EndPoint = Cgpointmake (40, 500);

Cgpathaddcurvetopoint (Pathref, NULL, 280, -30, Endpoint.x, ENDPOINT.Y);

Drop.path = Pathref;

Cgpathrelease (PATHREF);

return drop;

}

#pragma mark-Add animation group

-(void) Addanimationgroup {

Caanimationgroup *animationgroup = [Caanimationgroup animation];

Animationgroup.animations = @[[self Rotationanimation], [self dropanimation]];

Animationgroup.duration = 10;

BeginTime Animation start time

Cacurrentmediatime () Gets the current time from the start of calling the method starting 10 seconds after execution

Animationgroup.begintime = Cacurrentmediatime () + 1;

Animationgroup.removedoncompletion = NO;

Animationgroup.fillmode = Kcafillmodeboth;

Animationgroup.repeatcount = 5;

[Petal addanimation:animationgroup forkey:@ "group"];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

Animation Group (petals) falling with curves

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.