1 //2 //VIEWCONTROLLER.M3 //caanimationandviewanimation4 //5 //Created by Ys on 15/11/22.6 //Copyright (c) 2015 Ys. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A@property (Weak, nonatomic) Iboutlet UIView *Blackview; - - @end the - @implementationViewcontroller - -- (void) Viewdidload { + [Super Viewdidload]; - } + A-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event at { - //[self diycacoreanimation]; - //[self viewAnimation1]; - //[self viewAnimation2]; - [self viewAnimation3]; - in } - /** to * The problem with the core animation is 1. Its direct operation layer, and the view layer is not enough object-oriented. + * The properties of the 2.layer have not changed. The layer animation is an illusion, and the position property of the layer has never changed during the execution of the animation. - * Therefore in actual development, unless some effects are difficult to achieve, it is generally used to animate the view the */ *-(void) Diycacoreanimation $ {Panax NotoginsengCabasicanimation *anim =[cabasicanimation animation]; -Anim.keypath =@"position"; theAnim.tovalue = [Nsvalue valuewithcgpoint:cgpointmake ( $, $)]; +Anim.duration =0.5; AAnim.removedoncompletion =NO; theAnim.fillmode =kcafillmodeforwards; +Anim.Delegate=Self ; - [Self.blackView.layer Addanimation:anim forkey:nil]; $ $ } - --(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) Flag the { - //Diycacoreanimation After the animation is finished print the Position property of the discovered layer has never changed.WuyiNSLog (@"%@", Nsstringfromcgpoint (self.blackView.layer.position)); the } - Wu-(void) ViewAnimation1 - { About [UIView Beginanimations:nil context:nil]; $Self.blackView.center = Cgpointmake ( $, $); - [UIView commitanimations]; -NSLog (@"%@", Nsstringfromcgpoint (Self.blackView.center)); - } A +-(void) ViewAnimation2 the { -[UIView animatewithduration:1.0animations:^{ $Self.blackView.center = Cgpointmake ( $, $); the} completion:^(BOOL finished) { theNSLog (@"%@", Nsstringfromcgpoint (Self.blackView.center)); the }]; the } - in-(void) ViewAnimation3 the { the[UIView transitionWithView:self.blackView Duration:TenOptions:uiviewanimationoptiontransitionflipfromright animations:^{ About} completion:^(BOOL finished) { the }]; the } the @end
Coreanimation and view animations