iOS Development Core Animation VI: Animation Group

Source: Internet
Author: User

#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet UIView*Redview;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{cabasicanimation*anim =[cabasicanimation animation]; Anim.keypath=@"POSITION.Y"; Anim.tovalue= @ -; /** * 1:cabasicanimation: Mainly used for zooming, panning, transitions Catransiton animation is mainly used for scene switching, cakeyframeanimation: Keyframe animation, mainly used for icon jitter, etc. 2: in Cabasicanim ation, set Anim.removedoncompletion, the purpose is to not delete the animation after the end of the animation, Anim.fillmode = Kcafillmodeforwards; Set the animation mode, set these two properties, you can not let the animation after the end of the execution, reverts to the original position, but retains the state of the ending animation 3:caanimationgroup: She automatically performs animations in the array animations*/                //anim.removedoncompletion = NO;//anim.fillmode = kcafillmodeforwards;//    //[Self.redView.layer Addanimation:anim forkey:nil];cabasicanimation*ANIM2 =[cabasicanimation animation]; Anim2.keypath=@"Transform.scale"; Anim2.tovalue= @0.5;//anim2.removedoncompletion = NO;//anim2.fillmode = kcafillmodeforwards;//[Self.redView.layer addanimation:anim2 forkey:nil];Caanimationgroup*group =[Caanimationgroup animation]; //automatically executes all animated objects in the animations arrayGroup.animations =@[anim,anim2]; Group.removedoncompletion=NO; Group.fillmode=kcafillmodeforwards;    [Self.redView.layer Addanimation:group Forkey:nil]; }@end

You can perform multiple animations at the same time.

Create a group animation

Caanimationgroup *group = [Caanimationgroup animation];

Translation

Cabasicanimation *anim = [cabasicanimation animation];

Anim.keypath = @ "POSITION.Y";

Anim.tovalue = @400;

Scaling

Cabasicanimation *scaleanim = [cabasicanimation animation];

Scaleanim.keypath = @ "Transform.scale";

Scaleanim.tovalue = @0.5;

Set Animation Group Properties

Group.animations = @[anim,scaleanim];

Group.removedoncompletion = NO;

Group.fillmode = Kcafillmodeforwards;

Adding group animations

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

The benefit of using animation groups is that you don't need to add animations every time, setting properties when the animation finishes.

Just add the animation you want to perform to the animations array of the animation group,

The animation in the array is automatically executed when the group animation is added to the layer.

The properties that you set when the animation finishes are also set only once.

iOS Development Core Animation VI: Animation Group

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.