一个动画 Label (走马观花)

 

UILabel中一个水平移动的Label

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 300, 300)];

    UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)];

    label.text = @"啦啦啦拉拉,阿拉拉啊 ......";

    label.backgroundColor = [UIColor blackColor];

    label.textAlignment = UIBaselineAdjustmentAlignCenters;

    label.textColor = [UIColor whiteColor];

    [label7 setShadowColor:[UIColor redColor]];

    label7.shadowOffset = CGSizeMake(1.0, 1.0);

    CGRect frame = label7.frame;//一个矩形与Label7 一样的长

    frame.origin.x = -180;//这个矩形在父视图中X轴的开始动画位置

    label.frame = frame;

    [UIView beginAnimations:@"testAnimation" context:NULL];//开始动画

    [UIView setAnimationDuration:8.8f];//设置动画持续的时间(速率)

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];//设置动画的翻转方式

    [UIView setAnimationDelegate:self];//设置动画的运行的位置

    [UIView setAnimationRepeatAutoreverses:YES];//是不是设置为自动反向运动

    [UIView setAnimationRepeatCount:999999];//动画播放的次数

    frame = label.frame;

    frame.origin.x = 350;//矩形在父视图运动距离

    label.frame = frame;

    [UIView commitAnimations];

    

    [self.window addSubview:label];

    [label release];

    

原文地址:https://www.cnblogs.com/meixian/p/4531430.html