美文网首页
iOS简单跑马灯效果

iOS简单跑马灯效果

作者: 梵高的老巫婆 | 来源:发表于2018-12-20 14:27 被阅读25次
跑马灯.gif

代码如下

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 300, 0, 0)];
    label.text = @"没有生来天赋过人,面对人山人海只剩一些勤恳...";
    [label sizeToFit];
    [self.view addSubview:label];
    /**
     如果设置为YES 代表动画每次重复执行的效果跟上次相反
     [UIView setAnimationRepeatAutoreverses:YES];
     */
    [UIView beginAnimations:@"Marquee" context:NULL];
    //动画时长
    [UIView setAnimationDuration:15.0f];
    //动画节奏
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    //重复次数
    [UIView setAnimationRepeatCount:10000];
 
    CGRect lbframe = label.frame;
    lbframe.origin.x = - lbframe.size.width;
    label.frame = lbframe;
    [UIView commitAnimations];
    
}

相关文章

网友评论

      本文标题:iOS简单跑马灯效果

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