如何在我的应用程序中使用字幕? [英] How can i use marquee in my Application?

查看:125
本文介绍了如何在我的应用程序中使用字幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了如下所示的代码:

I wrote the code for marquee shown below---

- (void)viewDidAppear:(BOOL)animated {

     [super viewDidAppear:YES];
    //NSTimer *timer=[[NSTimer alloc] initWithFireDate:nil interval:.5 target:self selector:@selector(marqueDisplay) userInfo:nil repeats:YES];
    [NSTimer scheduledTimerWithTimeInterval:7.0
                                     target:self
                                   selector:@selector(marqueDisplay)
                                   userInfo:nil
                                    repeats:YES];

}

-(void)marqueDisplay
{
    NSString *theMessage = @"Hello, my name is Enigo Montoya. You killed my father, prepare to die";
    NSUInteger length = [theMessage length];
    NSLog(@"%d",length);
    if (length>69) {    
    messageSize = [theMessage sizeWithFont:[UIFont systemFontOfSize:14.0]];
    messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 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(-400, 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 / 60; // 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];  
    }
}

这可行,但这不能满足我的需要。 。
实际上,文本不是以循环形式移动,
i希望如果字符串长度大于60,则选择框开始并附加字符串。

this works but this is not satisfying my need... Actually the text is not moving in loop form, i want that if string length > 60 then marquee start and appended the string.

帮助我解决这个问题..
提前感谢。

Plz help me to solve this problem.. Thanks in advance.

推荐答案

://github.com/jeffhodnett/JHTickerViewrel =nofollow> https://github.com/jeffhodnett/JHTickerView

Here you go https://github.com/jeffhodnett/JHTickerView

这里是另一个 https://github.com/ConceitedCode/CCScrollingLabel

我希望您的问题能得到解决。

I hope your problem will be solved.

这篇关于如何在我的应用程序中使用字幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆