其實我在我的第六部分的tableview中的textfield和textview的第十一部分的textview。我的問題是當我點擊第六部分的texfield的鍵盤覆蓋文本字段,同樣的事情發生在textview.for我使用NSNotificationCenters。 和我寫的代碼爲:NS通知問題的textfield和textview
- (無效)viewWillAppear中:(BOOL)動畫{
tableView.tableFooterView=nil;
[self reloadView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:self.view.window];
[tableView reloadData];
}
- (無效)setViewMovedUp:(BOOL)movedUp {
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; //如果你想向上滑動視圖 CGRect rect = mview.frame; if(movedUp) {
rect.origin.y = rect.origin.y - kOFFSET_FOR_KEYBOARD; rect.size.height = rect.size.height + kOFFSET_FOR_KEYBOARD; } else { rect.origin.y = rect.origin.y + kOFFSET_FOR_KEYBOARD; rect.size.height = rect.size.height - kOFFSET_FOR_KEYBOARD; } mview.frame = rect;
[UIView commitAnimations];
}
(無效)keyboardWillShow:(NSNotification *)通知符 { // printf的( 「\ N鍵盤將顯示」); //鍵盤現在會顯示。取決於針對文本字段是有效的,向上移動或向下移動視圖適當
如果([notesTextView isFirstResponder] & & mview.frame.origin.y> = 0){
[自setViewMovedUp:YES]; } 否則如果([notesTextView isFirstResponder] & & mview.frame.origin.y < 0!) { [自setViewMovedUp:NO]; }否則如果([wineryTextField isFirstResponder] & & mview.frame.origin.y> = 0){
[自setViewMovedUp:YES]; } 否則如果([wineryTextField isFirstResponder] & & mview.frame.origin.y < 0!) { [自setViewMovedUp:NO]; }
}
(無效)keyboardWillHide:(NSNotification *)通知符 { // printf的( 「\ N鍵盤將隱藏」); //鍵盤現在會顯示。取決於針對文本字段是有效的,向上移動或向下移動視圖適當
如果([notesTextView isFirstResponder] & & mview.frame.origin.y> = 0){ [自setViewMovedUp:YES]; } 否則如果([notesTextView isFirstResponder] & & mview.frame.origin.y < 0!) { [自setViewMovedUp:NO]; }
否則如果([wineryTextField isFirstResponder] & & mview.frame.origin.y> = 0){ [自setViewMovedUp:YES]; } 否則如果([wineryTextField isFirstResponder] & & mview.frame.origin.y < 0!) { [自setViewMovedUp:NO]; }
}
(BOOL)的TextView:(UITextView的*)的TextView shouldChangeTextInRange:(NSRange)範圍 replacementText:(的NSString *)文本 { 如果([文本isEqualToString: @ 「\ n」 個]){
//event.eventNotes = notesTextView.text; if(textView==notesTextView) { //[self setViewMovedUp:NO]; [textView resignFirstResponder]; } return NO;
}
返回YES;
}
(BOOL)textFieldShouldReturn:(的UITextField *)的TextField {
如果(文本框== wineryTextField) { [自setViewMovedUp:NO]; [wineryTextField resignFirstResponder]; }}
以上就是我爲滾動編寫的代碼的view.but問題是有些時候當我點擊到文本框它,而不是滾動滾動理想管材具有相同的被髮梗下來textView.the問題是當我導航到另一個控制器,並返回並點擊更大的texfield或textview時得到的。
請給我一個完美的解決方案,我的問題。
感謝所有的u傢伙.....