views:

53

answers:

1

I met a really strange problem while using UITextView, I try to use "GrowStyle" of UITextView, wire up the frame with contentSize, turn off the .scrollEnabled, Build & Run: but when click the bottom of the screen, the keyboard showing up, the UITextView moves up a short distance, and its Top lines disappear, here is the code:

- (void)viewDidLoad {
    [super viewDidLoad];


 //Turn off the scrollEnabled.
 UITextView *growStyleText.scrollEnabled = NO;

 //Wire the growStyleText's contentSize to its frame, let it grow.
 CGRect selfHack = growStyleText.frame;
 selfHack.size = growStyleText.contentSize; 
 growStyleText.frame = selfHack;


 //Make a UIScrollView 

 UIScrollView *scroll.contentSize = selfHack.size;
 scroll.clipsToBounds = NO;
 [self.view insertSubview:scroll atIndex:1];

  //Add the TextView on the ScrollView, make it scrollable.
 [scroll addSubview:growStyleText];


}

After click the last line, Keyboard shows up, then the Top line Disappears! I thought about for all day long, anybody seen this? how can I make Top line moves up instead of disappear? hard question for me, guess there may be simple answers, thank you, very much.

alt text

alt text

+3  A: 

I don't know what you are trying to do, but, since UITextView is a subclass of UIScrollView, why do you need to create it as a subview of a UIScrollView? Then, in my experience, you can't get the contentSize of a UIScrollView before you add it to a view. I found this answer very useful

http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content

Hope it helps.

notme