Moving text like marquee style from bottom to top in iOS application. i have tried this long time using google search but i could not get perfect answer for this question please provide any code for this question. i an new to iOS application.
Asked
Active
Viewed 739 times
2
-
check my answer for that u just have to set only timeduration of finishing the animation 1 time then after it repeats – jayraj m.g. Feb 20 '14 at 04:59
-
Wow..!! You are so Intelligent. – Feb 20 '14 at 05:38
4 Answers
1
Try this
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
NSTimer *timer;
UILabel *label ;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
timer =[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollText:) userInfo:nil repeats:YES];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 250, 20)];
label.text =@"This is a string to be scroll";
[self.view addSubview:label];
}
-(void)scrollText:(id)parameter{
if (label.frame.origin.y <= 50) {
[label setFrame:CGRectMake(label.frame.origin.x, 400, label.frame.size.width, label.frame.size.height)];
}
else
[label setFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y-5, label.frame.size.width, label.frame.size.height)];
}
@end

Rajesh
- 10,318
- 16
- 44
- 64
-
make your label y position to 0 [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 250, 20)]; and in scrollText: method if (label.frame.origin.y <= 0){[label setFrame:CGRectMake(label.frame.origin.x, self.view.frame.size.height - 20, label.frame.size.width, label.frame.size.height)];} – Rajesh Feb 20 '14 at 06:03
0
You can find the same implementation in the below link. It's really awesome place for COCOA CONTROL.

Gyanendra Singh
- 1,483
- 12
- 15
0
Check this answer.
.h
NSTimer *timer;
float timeDuration;
.m
-(void)viewDidLoad {
[super viewDidLoad];
timeDuration=1.0f;
timer = [NSTimer scheduledTimerWithTimeInterval:timeDuration target:self selector:@selector(marqueeAnimation) userInfo:nil repeats:YES];
}
-(void)marqueeAnimation{
UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, -100, 100, 100)];
[imgView setImage:[UIImage imageNamed:@"root.PNG"]];
[self.view addSubview:imgView];
NSString *keyPath = @"transform.translation.y";
CAKeyframeAnimation *translation = [CAKeyframeAnimation animationWithKeyPath:keyPath];
translation.duration = timeDuration;
translation.autoreverses = NO;
NSMutableArray *values = [[NSMutableArray alloc] init];
[values addObject:[NSNumber numberWithFloat:0.0f]];
CGFloat height = [[UIScreen mainScreen] applicationFrame].size.height;
[values addObject:[NSNumber numberWithFloat:height]];
translation.values = values;
NSMutableArray *timingFunctions = [[NSMutableArray alloc] init];
[timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
translation.timingFunctions = timingFunctions;
[imgView.layer addAnimation:translation forKey:keyPath];
}

MarmiK
- 5,639
- 6
- 40
- 49

jayraj m.g.
- 625
- 5
- 18
0
Try this. This works. Try this in a sample app and then include it in your app.
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, retain) NSTimer *timer;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_txtView setText:@"hi..."];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(marqueeScroll) userInfo:nil repeats:YES];
}
-(void) marqueeScroll
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, _txtView.frame.origin.y-1.0, _txtView.frame.size.width, _txtView.frame.size.height)];
CGRect screen = [[UIScreen mainScreen] bounds];
if(_txtView.frame.origin.y <= 0 )
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, screen.size.height,_txtView.frame.size.width, _txtView.frame.size.height)] ;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Let me know if there are any errors.

z22
- 10,013
- 17
- 70
- 126