Caanimationgroup Animation Group and catransition transition animations and uiview transitions animation for core animations

Source: Internet
Author: User

1. Animation group, is a subclass of Caanimation, you can save a set of animated objects, after the Caanimationgroup object is added to the layer, all the animation objects in the group can concurrently run

1.1 Property Description:

Animations: A nsarray used to hold a set of animated objects by default, a set of animated objects runs concurrently, or you can change the start time of an animation by setting the BeginTime property of the animated object.

-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{

[Self rotateanimation];

[Self moveanimation];

Animation Group

Caanimationgroup *group = [Caanimationgroup animation];

Caanimation *animation1 = [self moveanimation];

Caanimation *animation2 = [self rotateanimation];

Group.animations = @[animation1,animation2];

Duration of animation Group

Group.duration = 5;

Group.repeatcount = maxfloat;

[Self.myImageView.layer Addanimation:group Forkey:nil];

}

-(Caanimation *) moveanimation{

1 Animation objects

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

Path

Cgmutablepathref path = cgpathcreatemutable ();

Drawing arcs

Cgpathaddarc (Path, NULL, self.view.center.x, self.view.center.y, 0, 2*M_PI, 0);

Animation.path = path;

Animation.duration = 5;

Animation.repeatcount = maxfloat;//infinitely Large

[Self.myImageView.layer addanimation:animation Forkey:nil];

return animation;

}

-(caanimation*) rotateanimation{

1 Animation objects

Cakeyframeanimation *animation = [cakeyframeanimation animationwithkeypath:@ "Transform.rotation.z"];

2

Animation.duration = 0.2;

Animation.repeatcount = maxfloat;

CGFloat angle = M_PI/30;

Animation.values = @[@0,@ (-angle), @0,@ (angle), @0];

[Self.myImageView.layer addanimation:animation Forkey:nil];

return animation;

}

2. Transition animation Catransition is a subclass of caanimation that is used to animate transitions and animate layers to move out of the screen and into the screen. iOS has less transition animations than Mac OS X

Uinavigationcontroller is the animation effect of pushing the controller's view into the screen via catransition

2.1 Animation Properties:
Type: Animation transition types

subtype: Animation transition Direction

startprogress: Start of Animation (percentage in overall animation)

endprogress: End of Animation (percentage in overall animation)

-(void) Viewdidload {

[Super Viewdidload];

index = 0;

Images = [Nsmutablearray arraywithcapacity:6];

for (int i =0; i<6; i++) {

NSString *string = [NSString stringwithformat:@ "%d.jpg", i+1];

UIImage *iamge = [UIImage imagenamed:string];

[Images ADDOBJECT:IAMGE];

}

Self.imageView.image = [UIImage imagenamed:@ "1.jpg"];

self.imageView.userInteractionEnabled = yes;//user interaction

Uiswipegesturerecognizer *swipe = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (ChangeImage )];

Swipe.direction = Uiswipegesturerecognizerdirectionleft;

[Self.imageview Addgesturerecognizer:swipe];

}

-(void) changeimage{

index++;

if (index>=6) {

index = 0;

}

Self.imageView.image = [images objectatindex:index];

Transition animations

Catransition *trans = [[Catransition alloc]init];

Property

Fade, ' Movein ', ' push ' and ' reveal

Trans.type = @ "Suckeffect";//Animation type

Trans.duration = 2;

Animation transition Direction

Fromleft ', ' fromright ', ' fromtop ' and Frombottom

Trans.subtype [email protected] "fromright";

[Self.imageView.layer Addanimation:trans Forkey:nil];

}

3.uiview Transitions Animation

+ (void) Transitionwithview: (UIView *) View Duration:    (nstimeinterval) Duration options: (uiviewanimationoptions) Options    animations: (void (^) (void)) animations completion: (void (^) (BOOL    finished)) completion;

Parameter description:

Duration: Duration of animation

View: Views that require a transition animation

Options: Types of transition animations

Animations: Place code that changes the properties of the view in this block

Completion: This block is automatically called after the animation is finished

#import "ViewController.h"

@interface Viewcontroller ()

{

UIView *view1;

UIView *view2;

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

View1 = [[UIView alloc]initwithframe:cgrectmake (0, 20, 200, 200)];

View1.backgroundcolor = [Uicolor Redcolor];

[Self.view Addsubview:view1];

View2 = [[UIView alloc]initwithframe:cgrectmake (0, 20, 200, 200)];

View2.backgroundcolor = [Uicolor Greencolor];

[Self.view Addsubview:view2];

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

}

-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{

Single transition animation

/*

[UIView transitionWithView:self.view Duration:2 options:uiviewanimationoptiontransitionflipfromleft animations:^{

Property changes for this view

View2.alpha = 0;

} completion:^ (BOOL finished) {

The call after completion

}];

*/

Dual transition animations

Note When you finish the animation, the Fromview is removed from the parent view

NSLog (@ "Subview before:%@", self.view.subviews);

[UIView transitionfromview:view2 toview:view1 duration:2 Options:uiviewanimationoptiontransitioncurlup Completion : ^ (BOOL finished) {

NSLog (@ "Subview after:%@", self.view.subviews);

}];

}

Caanimationgroup Animation Group and catransition transition animations and uiview transitions animation for core animations

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.