Keyframe Animation (2) The beating of the heart

Source: Internet
Author: User

//

Viewcontroller.m

Ui-no-38-1 Basic Animation Example 1

//

Created by Wei Rong on 15/9/17.

Copyright (c) 2015 Wei Rong. All rights reserved.

//

/*

Cakeyframeanimation also belongs to Capropertyanimation

Keyframe animation allows us to control the animation effect precisely it is the principle of the animation sequence inside the more critical frame out to set his animation effect

The Values property performs the path of the animation track

The Path property performs an array of animation tracks

*/

#import "ViewController.h"

@interface Viewcontroller ()

{

Calayer *petallayer;

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.view.backgroundColor = [Uicolor Whitecolor];

Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:[uiscreen mainscreen].bounds];

NSString *path = [[NSBundle mainbundle] pathforresource:@ "deciduous" oftype:@ "jpg"];

Imageview.image = [UIImage Imagewithcontentsoffile:path];

[Self.view Addsubview:imageview];

[Self addpetal];

}

-(void) Addpetal {

NSString *path = [[NSBundle mainbundle] pathforresource:@ "petal" oftype:@ "jpg"];

UIImage *petal = [UIImage Imagewithcontentsoffile:path];

Petallayer = [[Calayer alloc] init];

Petallayer.bounds = CGRectMake (0, 0, petal.size.width, petal.size.height);

Petallayer.position = Cgpointmake (150, 250);

Petallayer.contents = (ID) petal. Cgimage;

[Self.view.layer Addsublayer:petallayer];

}

-(void) Dropanimation {

Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "position"];

Animation.fromvalue = [Nsvalue valueWithCGPoint:petalLayer.position];

Animation.tovalue = [Nsvalue valuewithcgpoint:cgpointmake (150, 600)];

Animation.duration = 5;

Animation.removedoncompletion = NO;

Animation.fillmode = Kcafillmodeboth;

[Petallayer addanimation:animation forkey:@ "Show"];

}

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) Event {

[Self dropanimation];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end


Keyframe Animation (2) The beating of the heart

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.