How to move text from right to left in iOS programmatically

后端 未结 9 1778
野趣味
野趣味 2020-12-28 11:33

I want to show some text in my app like moving text (Scrolling with animation from right to left). How to do this programmatically?

I took UIViewcontroller

9条回答
  •  春和景丽
    2020-12-28 11:33

    First of all you take a label in your view and set its frame out of view as following.

     - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        la = [[UILabel alloc]initWithFrame:CGRectMake(320, 100, 200, 60)];
    
        la.text = @"This is my music line";
    
        [self.view addSubview:la];
    
        [NSTimer scheduledTimerWithTimeInterval:2.0
                                         target:self
                                       selector:@selector(LabelAnimation)
                                       userInfo:nil
                                        repeats:YES];
    
    }
    

    Now that label give animation as below method called in ViewDidLoad

    -(void)LabelAnimation
    {
        [UIView animateWithDuration:3.0f delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{
            la.frame = CGRectMake(-320, 100, 200, 60);
        } completion:^(BOOL finished)
         {
             la.frame = CGRectMake(320, 100, 200, 60);
         }];
    
    }
    

    output is below.

    enter image description here

提交回复
热议问题