您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页跑马灯动画实现方式(一)UIView animate block

跑马灯动画实现方式(一)UIView animate block

来源:二三四教育网

通过UIView animate block 方式简单实现

-(void)startAnimation{

      //取消所有的动画

      //[self.aUILabel.layer removeAllAnimations];

     //计算实际text大小

     CGSizetextSize =            [self.aUILabel.textsizeWithAttributes:@{NSFontAttributeName:self.aUILabel.font}];

     //保存label的frame值

     CGRectlframe =self.aUILabel.frame;

     //用计算出来的text的width更改frame的原始width

    lframe.size.width= textSize.width;

    //从屏幕最右边向左边移动

    lframe.origin.x=self.view.bounds.size.width;

   //用新值更改label的原frame值

   self.aUILabel.frame= lframe;

   //计算动画x移动的最大偏移:屏幕width+text的width

   floatoffset = textSize.width+self.view.bounds.size.width;

   [UIView animateWithDuration:10.0

                delay:0

                options:UIViewAnimationOptionRepeat//动画重复的主开关

                |UIViewAnimationOptionCurveLinear//动画的时间曲线

                animations:^{

                    self.aUILabel.transform=CGAffineTransformMakeTranslation(-offset,0);

}

 completion:^(BOOLfinished) {

}

     ];

}


附图片:

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务