iOS简单跑马灯效果

跑马灯.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简单跑马灯效果)