iOS animation implicit, explicit, page-flipping

Source: Internet
Author: User

Viewcontroller.m

iOS animations 0817

//

Created by Zhang Yanfeng on 15/8/17.

Copyright (c) 2015 Zhang Yanfeng. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

@property (Weak, nonatomic) Iboutlet Uiimageview *imageview;

-(Ibaction) Doanimationbutton: (ID) sender;

-(Ibaction) Doleftbutton: (ID) sender;

-(Ibaction) Dorightbutton: (ID) sender;

-(Ibaction) Doupbutton: (ID) sender;

-(Ibaction) Dodownbutton: (ID) sender;

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Additional setup after loading the view, typically from a nib.

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

-(Ibaction) Doanimationbutton: (ID) Sender {

/******** Implicit animation ********/

/*

[UIView beginanimations:nil context:null];//animation start flag

Define an affine transformation

Cgaffinetransform movetrans=cgaffinetransformmaketranslation (300, 600);

cgaffinetransformmaketranslation//changing the position of a function

cgaffinetransformmakerotation//k Control rotation

cgaffinetransformmakescale//Control Zoom

[_imageview.layer Setaffinetransform:movetrans];

[UIView commitanimations];//Commit Animation

*/

/******** Explicit Animation ********/

When defining a display animation, we do not have to define calayer changes, and we do not have to do it, but instead, we define the animation individually by Cabasicanimation, where each animation contains its own properties and is then added to the layer through the Addanimation: method.

/*

Cabasicanimation *basic=[cabasicanimation animationwithkeypath:@ "Opacity"];//opacity indicates transparency

BASIC.DURATION=6.0;//6 the transparency to 0 in seconds

Basic.fromvalue=[nsnumber numberwithfloat:0.2];//Initial Transparency

Basic.tovalue=[nsnumber numberwithfloat:1.0];//Final Transparency

basic.cumulative=yes;//setting transparency increments

[_imageview.layer addanimation:basic forkey:@ "animateopacity"];

Cgaffinetransform movetrans1=cgaffinetransformmaketranslation (300, 600);

Cabasicanimation *basic_move=[cabasicanimation animationwithkeypath:@ "transform"];//prepare function (prepare for panning)

basic_move.duration=6.0;

Catransform3dmakeaffinetransform affine transform to 3D effect (affine cannot be applied directly to explicit animations)

Basic_move.tovalue=[nsvalue Valuewithcatransform3d:catransform3dmakeaffinetransform (moveTrans1)];

[_imageview.layer addanimation:basic_move forkey:@ "AnimateTransform2"];

*/

/******** Key-Frame animation ********/

/*

Cakeyframeanimation *keyanimation=[cakeyframeanimation animationwithkeypath:@ "opacity"];//transparency

keyanimation.duration=6.0;//Animation time

Keyanimation.values=[nsarray Arraywithobjects:[nsnumber Numberwithfloat:0.0],[nsnumber numberWithFloat:0.6],[ NSNumber numberwithfloat:1.0], nil];//

Keyanimation.keytimes=[nsarray Arraywithobjects:[nsnumber Numberwithfloat:0.0],[nsnumber numberWithFloat:0.3],[ NSNumber numberwithfloat:1.0], nil];

[_imageview.layer addanimation:keyanimation forkey:@ "Animateopcaty"];

Cgaffinetransform movetrans2=cgaffinetransformmaketranslation (300, 600);

Cabasicanimation *basic_move2=[cabasicanimation animationwithkeypath:@ "transform"];

basic_move2.duration=6.0;

Basic_move2.tovalue=[nsvalue Valuewithcatransform3d:catransform3dmakeaffinetransform (MOVETRANS2)];

[_imageview.layer addanimation:basic_move2 forkey:@ "AnimateTransform2"];

*/

}

The system comes with a reverse rotation picture (up or down)

-(Ibaction) Doleftbutton: (ID) Sender {

Three times left not returned

[UIView Beginanimations:nil Context:null];

[UIView setanimationduration:1.5f];//Animation time

[UIView setanimationcurve:uiviewanimationcurveeaseout];//sets the animation curve mode (the overall change time curve of the animation, including the start slow later fast, start fast later slow, uniform curve)

[UIView setanimationrepeatautoreverses:no];//sets the animation to do a reverse operation

[UIView setanimationrepeatcount:3];//execution times

[UIView setanimationtransition:uiviewanimationtransitionflipfromleft ForView:self.view cache:yes];//

[UIView commitanimations];

}

-(Ibaction) Dorightbutton: (ID) Sender {

Three times right there back

[UIView Beginanimations:nil Context:null];

[UIView setanimationduration:1.5f];

[UIView Setanimationcurve:uiviewanimationcurveeaseout];

[UIView Setanimationrepeatautoreverses:yes];

[UIView setanimationrepeatcount:3];//execution times

[UIView setanimationtransition:uiviewanimationtransitionflipfromright ForView:self.view Cache:yes];

[UIView commitanimations];

}

-(Ibaction) Doupbutton: (ID) Sender {

[UIView Beginanimations:nil Context:null];

[UIView setanimationduration:1.5f];

[UIView Setanimationcurve:uiviewanimationcurveeaseout];

[UIView Setanimationrepeatautoreverses:yes];

[UIView Setanimationtransition:uiviewanimationtransitioncurlup ForView:self.view Cache:yes];

[UIView commitanimations];

}

-(Ibaction) Dodownbutton: (ID) Sender {

[UIView Beginanimations:nil Context:null];

[UIView setanimationduration:1.5f];

[UIView Setanimationcurve:uiviewanimationcurveeaseout];

[UIView Setanimationrepeatautoreverses:yes];

[UIView Setanimationtransition:uiviewanimationtransitioncurldown ForView:self.view Cache:yes];

[UIView commitanimations];

}

iOS animation implicit, explicit, page-flipping

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.