2013-10-04 5 views
0

UiscrollView에 나타나는 키보드에 문제가 있습니다. 키보드가 스크롤 뷰에 대해 표시 될 때 문자 필드가 사라짐

는 난 UITextFields 10 행의 각 행은, 각 텍스트 필드 높이가 50 픽셀이다 5 텍스트 필드를 갖고 추가로이있는 ScrollView

scrlView=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 140, 1000, 600)]; 
scrlView.scrollEnabled=YES; 
scrlView.showsVerticalScrollIndicator=YES; 
scrlView.bounces=NO; 

같은있는 UIScrollView했다. 이제까지는 UIKeyboardWillHideNotification이

- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
    { 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 

    [UIView animateWithDuration:0.4 animations:^{ 
    scrlView.contentInset = contentInsets; 
    }]; 
    scrlView.scrollIndicatorInsets = contentInsets; 
} 

를 보낼 때이 코드

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(keyboardWasShown:) 
              name:UIKeyboardDidShowNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(keyboardWillBeHidden:) 
              name:UIKeyboardWillHideNotification object:nil]; 


    - (void)keyboardWasShown:(NSNotification*)aNotification 
    { 
NSDictionary* info = [aNotification userInfo]; 
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
CGRect bkgndRect = selectetTxtfld.superview.frame; 
bkgndRect.size.height += kbSize.height; 
[selectetTxtfld.superview setFrame:bkgndRect]; 
[scrlView setContentOffset:CGPointMake(0.0, selectetTxtfld.frame.origin.y) animated:YES]; 
} 

} 호출

//을 시도하는 것이 keyBoard.For에 의해 중복되는 텍스트 필드 편집을 시도하지만, 텍스트 필드하지 않는 경우 keyboardview.it는 scrollview ypoint 위치에 나타납니다

이 문제에 대해 도와주세요. 많은 답을 보았습니다. StackOverFlow.But 내 문제를 해결하지 않았다

답변

1
- (void)keyboardWillBeHidden:(NSNotification*)aNotification { 

NSDictionary* info = [aNotification userInfo]; 
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
CGFloat offSetAfterKeyboardIsDisplayed = scrlview.contentOffset.y + kbSize.height; 

[UIView animateWithDuration:0.3 animations:^{ 
//adding content inset at the bottom of the scrollview 
    scrlView.contentInset = UIEdgeInsetMake(0,0,kbSize.height,0); 
    [scrlview setContentOffset:offSetAfterKeyboardIsDisplayed] 
}]; 
} 


- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
{ 

NSDictionary* info = [aNotification userInfo]; 
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
CGFloat offSetAfterKeyboardResigns = scrlview.contentOffset.y - kbSize.height; 

[UIView animateWithDuration:0.3 animations:^{ 
    scrlView.contentInset = UIEdgeInsetsZero; 
    [scrlview setContentOffset:offSetAfterKeyboardResigns] 
}]; 
} 
+0

scrlView.contentInset에서 오류 표시 = UIEdgeInsetMake (0,0, kbSize.height, 0); 호환되지 않는 유형 'int'에서 'UIEdgeInsets'(일명 'struct UIEdgeInsets')에 할당 – sudheer

+0

[scrlView setContentOffset : offSetAfterKeyboardIsDisplayed]에서 오류 표시 '호환되지 않는 유형'CGPoint '(일명'const float ')'const CGFloat ' 'CGPoint 구조체') – sudheer

+0

다시 응답하기위한 tnks입니다. 지금은 내게 매우 중요합니다. – sudheer

1

in keyboardWasShown : 1. 키보드의 높이와 동일한 값으로 scrollview의 하단에 내용을 추가합니다. 2. setContentOffset = 현재 오프셋 + 키보드 높이. 주 : 1 & 3 keyboardWillBeHidden에서 0.30

EqualTo가 시간과 함께 애니메이션 블록에서 수행되어야한다 1.set contentInset = UIEdgeInsetsZero setContentOffset = 2 오프셋 전류 - 키보드의 높이. 주 : 1 & 3 0.30

EqualTo가 기간이 애니메이션 블록에서 수행해야이 UR의 문제 : 당신은 몇 가지 샘플 code.I 오전으로 브리핑 할 수 있습니다 응답 .PLS에 대한

+0

감사를 해결한다 새로운 xcode deve – sudheer

관련 문제