I want to animate UILabel in form of news read ...ex:- How are you is my UILabel . I want it to move to left and loop once the last word is moved complete left. If anyone can help me?
Thanks
I want to animate UILabel in form of news read ...ex:- How are you is my UILabel . I want it to move to left and loop once the last word is moved complete left. If anyone can help me?
Thanks
What have you tried so far?
Take a look at UIView's animation methods, such as animateWithDuration:animations:completion:
. You can animate the view's frame
, and using the completion handler you can call another method to move the view back.
Essentially, think of the animate
method as going one way, and the completion handler as going the other way. Call the entire thing on a timer/loop, and you'll have it going continuously back and forth
[UIView animateWithDuration:0.3 animations:^{
label.frame = frame;
}];
'frame' should be the new frame of the label. You can use this method to animate changes on all UIKit views.
Please do some basics before ask question.
Anyway, there are two common ways to achieve that.
Using animateWithDuration:animations:completion:, by which you add the label to the view and animate through a time by setting the destination frame in animation: block.Like:
//set initial frame for the label and add to the self.view
[UIView animateWithDuration:/*animation duration*/ animations:^{
//set destination frame of the label, only change x-axis value
} completion:^(BOOL finished) {
}];
Or you can use NSTimer if you want a continuous loop of this animation. For example:
[NSTimer scheduledTimerWithTimeInterval:/*label_change_time*/ target:nil selector:@selector(moveLabelToLeft:) userInfo:nil repeats:YES];
and in the moveLabelToLeft: set the difference of x-axis value over the label_change_time