【问题标题】:How to stop the horizontal scrolling programmatically?如何以编程方式停止水平滚动?
【发布时间】:2010-05-10 07:56:05
【问题描述】:

我在 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 ));  

我应该怎么做才能停止水平滚动?

谢谢。

【问题讨论】:

    标签: cocoa-touch uitextview cocos2d-iphone


    【解决方案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];   
    

    它对我有用。它只上下滚动,也上下弹跳。

    谢谢。

    【讨论】:

    • 所以你只硬编码较小的字体大小?我猜你可能已经计算了 textView 的 contentView 边界并调整了字体大小以使其适合 textView
    猜你喜欢
    • 2015-11-09
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多