2010-05-10 88 views
2

我在cocos2d的CCLayer中有一個UITextView * textView。文本在水平和垂直方向都滾動。但是,我需要它在垂直方向上滾動和反彈。 如何以編程方式停止水平滾動?如何以編程方式停止水平滾動?

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100,200, windowSize.height/2,windowSize.width/2)]; 
    textView.backgroundColor = [UIColor clearColor]; 
textView.text = @"I am First enemy I am First enemy I am First enemy I am First enemy I am First enemy I am First enemy I am First enemy I am First enemy"; 
[textView setEditable:NO]; 
textView.font = [UIFont fontWithName:@"Helvetica" size:24.0f]; 
CGPoint location = CGPointMake(200, 160); 
textView.showsHorizontalScrollIndicator = NO; 
    //textView.bounces = NO; 
//textView.alwaysBounceVertical = YES; 

    textView.center = location; 
    textView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90.0f)); 

我該怎麼做才能停止水平滾動?

謝謝。

回答

1

我不知道這是否是好的解決方案。但它爲我工作。我在這裏張貼,以便任何人可以糾正它。

textView = [[UITextView alloc] initWithFrame:CGRectMake(100,200,200 ,200)]; 
    textView.backgroundColor = [UIColor clearColor]; 
    NSLog(@"description: %@", enemyDescription); 
    textView.text = enemyDescription; 
    [textView setEditable:NO]; 
    textView.font = [UIFont fontWithName:@"Helvetica" size:14.0f]; 
    CGPoint location = CGPointMake(200, 160); 
    textView.showsHorizontalScrollIndicator = NO; 
    textView.alwaysBounceVertical = YES; 

    textView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90.0f)); 

    [[[CCDirector sharedDirector]openGLView]addSubview:textView]; 

它爲我工作。它只能上下滾動,也會上下跳動。

謝謝。

+0

所以你只硬編碼較小的字體大小?我猜你可能已經計算了textView的contentView邊界並調整了字體大小,以便它適合textView – kervich 2013-04-02 12:15:51