我有相當長的形式在ipad有uitextfields和uitextviews。當鍵盤使用鍵盤通知隱藏uitextfield時,我可以向上滾動。但是當uitextview變爲活動狀態並且它位於鍵盤下方時,它足夠滑動,以便我可以看到閃爍的光標。這是正常的行爲?如果不是,我怎麼可以向上滾動整個uitextview,以便在編輯時可以看到整個uitextview?ipad鍵盤隱藏uitextView
這裏是代碼..
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark Keyboard Events
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return NO;
}
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-(void)keyboardWasShown:(NSNotification *)aNotification
{
if (displayKeyboard==YES) {
return;
}
NSDictionary* info = [aNotification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
//NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
offset = _scrollView.contentOffset;
CGRect viewFrame = _scrollView.frame;
viewFrame.size.height -= keyboardSize.height-tabbarHt;
_scrollView.frame = viewFrame;
CGRect textFieldRect = [activeField frame];
textFieldRect.origin.y += 10;
[_scrollView scrollRectToVisible: textFieldRect animated:YES];
displayKeyboard = YES;
}
-(void)keyboardWillBeHidden:(NSNotification *)aNotification
{
if (!displayKeyboard) {
return;
}
_scrollView.frame = CGRectMake(0, 0, 1024, 655);
_scrollView.contentOffset =offset;
displayKeyboard = NO;
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
activeField = textField;
return YES;
}
你必須設置在UITextViewDelegate方法滾動的方法 – Hiren 2012-07-17 09:29:31
@CocoaMatters你能告訴我怎麼去做這件事嗎? – southpark 2012-07-17 09:34:55
你如何爲UITextField做些什麼? – Hiren 2012-07-17 09:35:59