IOS Calayer jitter Effect

Source: Internet
Author: User

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

Related Article

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.