我想縮小我的UITextView的大小(至221像素),當鍵盤出現時,並恢復到正常高度(337像素)時,鍵盤消失,所以我這樣做:試圖設置高度的UITextView
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect bkgndRect = inkTextField.superview.frame;
bkgndRect.size.height += kbSize.height;
[inkTextField.superview setFrame:bkgndRect];
[inkScroller setContentOffset:CGPointMake(0.0, inkTextField.frame.origin.y-kbSize.height) animated:YES];
inkTextField.frame=CGRectMake(1, -5, 285, 221);
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
inkScroller.contentInset = contentInsets;
inkScroller.scrollIndicatorInsets = contentInsets;
inkTextField.frame=CGRectMake(1, -5, 285, 337);
}
但這不起作用。它只是使用XIB文件中定義的高度。
我不會要做到這一點了原來的想法工作的地方,它只是應該滾動,因爲我輸入,以便我的文本不隱藏在鍵盤後面。但是,當我輸入時,它不會精確地向上滾動。它像3條線一樣落後。我從蘋果公司得到了這段代碼,但只是添加了inkTextField.frame = CGRectMake ...因爲原始文件沒有工作 – bitmoe