美文网首页技巧买不来的iOS实用技巧
跑马灯动画实现方式(一)UIView animate block

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

作者: GodfansMa | 来源:发表于2016-03-28 17:52 被阅读279次

通过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) {

}

     ];

}


附图片:

相关文章

网友评论

    本文标题:跑马灯动画实现方式(一)UIView animate block

    本文链接:https://www.haomeiwen.com/subject/wabjlttx.html