欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS动画-定时对UIView进行翻转和抖动的方法

程序员文章站 2024-02-08 12:31:22
(翻转)方式一: [nstimer scheduledtimerwithtimeinterval:3.f repeats:yes block:^(nstimer...

(翻转)方式一:

[nstimer scheduledtimerwithtimeinterval:3.f repeats:yes block:^(nstimer * _nonnull timer) {
      cabasicanimation* rotationanimation = [cabasicanimation animation];;
      rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation.y"];
      rotationanimation.tovalue = [nsnumber numberwithfloat: m_pi * 2.0 ];
      rotationanimation.duration = 1;
      // 切换界面保证动画不停止
      rotationanimation.removedoncompletion = no;
      rotationanimation.repeatcount = 1;
      [self.bindcardimageview.layer addanimation:rotationanimation forkey:@"rotationanimation"];
    }];

(翻转)方式二(这种方式较好一些):

cabasicanimation *waitanimation = [cabasicanimation animation];
    waitanimation.tovalue = [nsnumber numberwithfloat:1.0];
    waitanimation.duration = 3.f;
    waitanimation.begintime = 3.f;

    cabasicanimation* rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation.y"];
    rotationanimation.tovalue = [nsnumber numberwithfloat: m_pi * 2.0 ];
    rotationanimation.duration = 1.f;

    caanimationgroup *group = [caanimationgroup animation];
    group.duration = 4.f;
    group.repeatcount = cgfloat_max;
    group.removedoncompletion = no;

    [group setanimations:@[waitanimation, rotationanimation]];

    [self.bindcardimageview.layer addanimation:group forkey:@"bindcardimageviewanimation"];

抖动:

cabasicanimation* shake = [cabasicanimation animationwithkeypath:@"transform.rotation.z"];
  //设置抖动幅度
  shake.fromvalue = [nsnumber numberwithfloat:-0.2];
  shake.tovalue = [nsnumber numberwithfloat:+0.2];
  shake.duration = 0.1;
  shake.autoreverses = yes; //是否重复
  shake.repeatcount = 3;

  [itemview.iconimageview.layer addanimation:shake forkey:@"imageview"];

以上这篇ios动画-定时对uiview进行翻转和抖动的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。