UITextView内容宽度随着打字时高度的增加而缩小。为什么我看到这种行为?

时间:2012-05-25 23:29:42

标签: ios cocoa-touch uitextview

在UITextView委托方法中,当我输入时,我正在打印它的框架和内容大小。

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
     {   
               NSLog(@"textView Frame: %@ Content Size:%@",NSStringFromCGRect(textView.frame),NSStringFromCGSize(textView.contentSize));
               return YES;
      }

我所看到的是非常令人费解的。随着文字向上滚动,内容宽度不断缩小,因为我输入了文字。 textView的框架保持不变。为什么我看到这种行为?

2012-05-25 16:18:53.349  textView Frame: {{20, 12}, {65, 40}} Content Size:{271, 74}
2012-05-25 16:18:53.405  textView Frame: {{20, 12}, {65, 40}} Content Size:{270, 74}
2012-05-25 16:18:53.412  textView Frame: {{20, 12}, {65, 40}} Content Size:{269, 74}
2012-05-25 16:18:53.508  textView Frame: {{20, 12}, {65, 40}} Content Size:{268, 132}
2012-05-25 16:18:53.516  textView Frame: {{20, 12}, {65, 40}} Content Size:{267, 132}
2012-05-25 16:18:53.613  textView Frame: {{20, 12}, {65, 40}} Content Size:{266, 132}
2012-05-25 16:18:53.621  textView Frame: {{20, 12}, {65, 40}} Content Size:{265, 132}
2012-05-25 16:18:53.684  textView Frame: {{20, 12}, {65, 40}} Content Size:{264, 132}
2012-05-25 16:18:53.709  textView Frame: {{20, 12}, {65, 40}} Content Size:{263, 132}
2012-05-25 16:18:53.789  textView Frame: {{20, 12}, {65, 40}} Content Size:{262, 132}
2012-05-25 16:18:53.813  textView Frame: {{20, 12}, {65, 40}} Content Size:{261, 132}
2012-05-25 16:18:53.868  textView Frame: {{20, 12}, {65, 40}} Content Size:{260, 132}
2012-05-25 16:18:53.949  textView Frame: {{20, 12}, {65, 40}} Content Size:{259, 132}
2012-05-25 16:18:54.029  textView Frame: {{20, 12}, {65, 40}} Content Size:{258, 132}
2012-05-25 16:18:54.045  textView Frame: {{20, 12}, {65, 40}} Content Size:{257, 132}
2012-05-25 16:18:54.173  textView Frame: {{20, 12}, {65, 40}} Content Size:{256, 132}
2012-05-25 16:18:54.180  textView Frame: {{20, 12}, {65, 40}} Content Size:{255, 132}
.......
2012-05-25 16:19:00.420 textView Frame: {{20, 12}, {65, 40}} Content Size:{119, 1524}
2012-05-25 16:19:00.477 textView Frame: {{20, 12}, {65, 40}} Content Size:{118, 1582}

修改 更多细节。 当我创建这个textView时,我用更大的帧大小创建它并缩小它并将其添加到它的superview中。我这样做的原因是,当textView的superview被缩放时,textView中的文本不会变得模糊。

float Scale = 5.0;
CGRect rect = ... (original frame of myTextView)
myTextView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,rect.size.width*Scale, rect.size.height*Scale)];
myTextView.transform = CGAffineTransformMakeScale(1.0/originalScale,1.0/originalScale);

这种方法运作良好但似乎导致了这个错误。 (因为当我关闭缩放时,不会发生这个问题。)

0 个答案:

没有答案