1

在 UITextView 委托方法中,我在输入时打印它的 Frame 和 Content Size。

    - (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 时,我正在创建它具有更大的帧大小并将其缩小并将其添加到它的超级视图中。我这样做的原因是,当 textView 的超级视图被缩放时,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);

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

4

0 回答 0