Way One
1- (void) Shakeanimationforview: (UIView *) View2 {3Calayer *layer =[view layer];4Cakeyframeanimation *animation =[cakeyframeanimation animation];5Animation.keypath =@"position.x";6Animation.values = @[@0, @5, @Ten, @-Ten, @Ten, @5, @0 ];7Animation.keytimes = @[@0, @(1/6.0),@(2/6.0), @(3/6.0), @(5/6.0),@(2/6.0), @1 ];8Animation.duration =0.4;9 TenAnimation.additive =YES; One A[Layer addanimation:animation Forkey:@"Shake"]; -}
Way Two
1- (void) Shakeanimationforview: (UIView *) View2 3 { 4 //gets the layer of the current view5Calayer *viewlayer =View.layer;6 7 //get the current view location8Cgpoint position =viewlayer.position;9 Ten //two end locations to move OneCGFloat scale =5.0f; ACgpoint beginposition = cgpointmake (position.x +Scale , POSITION.Y); -Cgpoint endposition = Cgpointmake (Position.x-Scale , POSITION.Y); - the //Set Animation -Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"position"]; - - //set the form of motion + [animation settimingfunction:[camediatimingfunction Functionwithname:kcamediatimingfunctiondefault]; - + //Set Start position A [animation Setfromvalue:[nsvalue valuewithcgpoint:beginposition]; at - //Set End Position - [animation Settovalue:[nsvalue valuewithcgpoint:endposition]; - - //Set auto-invert - [animation Setautoreverses:yes]; in - //Set the time to[Animation setduration:0.1]; + - //Number of settings the[Animation Setrepeatcount:3]; * $ //Add on animationPanax Notoginseng [Viewlayer addanimation:animation forkey:nil]; - the}
IOS Calayer jitter Effect