键盘在UITextView中吃我的*文本行!

问题描述:

我在使用UITextView时遇到了一个非常奇怪的问题,我尝试使用UITextView的“GrowStyle”,用contentSize连接帧,关闭.scrollEnabled,Build &运行:但是当点击屏幕底部时,键盘显示起来,在UITextView的向上移动一小段距离,它的最高线消失,这里是代码:键盘在UITextView中吃我的*文本行!

- (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]; 


} 

单击最后一个行之后,键盘显示出来,然后将顶线消失!我想了一整天,有人看到了这个?我怎样才能让顶线上移而不是消失?对我来说很难回答,猜测可能有简单的答案,非常感谢。

alt text

alt text

+0

你有没有想过这一个?我与我的UITextView有完全相同的问题... – 2011-11-21 18:46:32

我不知道你正在尝试做的,但由于UITextView的是的UIScrollView的子类,为什么你需要创建它作为一个UIScrollView的子视图? 然后,根据我的经验,在添加到视图之前,您无法获取UIScrollView的contentSize。 我发现这个答案是非常有用的

How do I size a UITextView to its content?

希望它能帮助。