我想从左到右连续制作文字。我已经使用以下代码,如果任何人有答案请告诉我thnx在高级.....
NSString *theMessage = @"Hello, my name is Enigo Montoya. You killed my father, prepare to die";
messageSize = [theMessage sizeWithFont:[UIFont systemFontOfSize:14.0]];
messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, messageSize.width, 19)]; //x,y,width,height
[messageView setClipsToBounds:YES]; // With This you prevent the animation to be drawn outside the bounds.
[self.view addSubview:messageView];
lblTime = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 19)]; //x,y,width,height
[lblTime setBackgroundColor:[UIColor darkGrayColor]];
lblTime.font = [UIFont systemFontOfSize:14];
[lblTime setText:theMessage];
[lblTime setTextAlignment:UITextAlignmentLeft];
lblTime.frame = CGRectMake(0, 0, messageSize.width, 19); //x,y,width,height
[messageView addSubview:lblTime];
float duration = messageSize.width / 30; // This determines the speed of the moving text.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
lblTime.frame = CGRectMake(-messageSize.width, 0, messageSize.width, 19); //x,y,width,height
[UIView commitAnimations];
答案 0 :(得分:0)
k我已经完成了这个代码,只是检查出来的人
- (void)marqueeMessage:(id)sender
{
// For Marquee text From left To right with Continously
NSString *theMessage = @"WelCome To Wishing Well";
messageSize = [theMessage sizeWithFont:[UIFont systemFontOfSize:20.0]];
messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, messageSize.width, 19)]; //x,y,width,height
[messageView setClipsToBounds:YES]; // With This you prevent the animation to be drawn outside the bounds.
UILabel *label = [[UILabel alloc] initWithFrame:(CGRectMake(0, 20, messageSize.width, messageSize.height))];
[label setText:theMessage];
label.backgroundColor=[UIColor darkGrayColor];
[self.view addSubview:label];
float duration = messageSize.width / 60; // This determines the speed of the moving text.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:messageView cache:YES];
// [UIView beginAnimations:@"test" context:nil];
// [UIView setAnimationDuration:10];
[UIView setAnimationDidStopSelector:@selector(marqueeMessage:)];
[UIView setAnimationDelegate:self];
label.frame = CGRectMake(360,20,messageSize.width,messageSize.height);
[UIView commitAnimations];
}
然后你必须把下面的代码用于连续从左到右的字幕文本
- (void)viewDidLoad
{
[super viewDidLoad];
[self marqueeMessage:messageView];
}
我希望它为所有人工作@alfa ...