1

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を作成するときは、はるかに大きなフレームサイズで作成し、縮小してスーパービューに追加します。これを行う理由は、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