2014-06-23 20 views
0

我想連續從左到右的方向選取文本。我曾嘗試使用下面的代碼使用,如果任何人有答案,請告訴我,在日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

它會完美選取框只有一次它不會連續選取文本,所以請告訴我 – alfa

+0

我猜'UIViewAnimationTransitionNone'是不夠的。如果我記得好,還有一個重複選項和一個相反的選項? – Larme

回答

0

き已經使用此代碼做只是檢查出來傢伙

- (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所有的人......