2013-03-08 2 views
0

this 샘플 프로젝트를 사용하고 있는데 내가 수행하고자하는 것은 UITextField을 뷰에 놓을 때 키보드 아래에 UITextField이있을 때 뷰가 위로 이동합니다 조금.UIScrollView로 스 와이프하고 키보드를 사용할 때 뷰를 위로 이동합니다.

나는 프로젝트 this에서 TPKeyBoardAvoidingScrollView 클래스를 사용했습니다. 그러나 UITextField을 클릭하면보기가 위로 이동하고 모든 항목이 정상적으로 작동하지만 배경을 클릭 할 때 일반 화면 크기를 복원하고 키보드를 닫는 대신 뷰에서 고정하는 대신 첫 번째보기로 되돌아갑니다. 우리는 그 순간에있었습니다.

또한 키보드가 튀어 나올 때 왼쪽 및 오른쪽으로 스크롤 할 수 있습니다. 어떻게 해결할 수 있습니까? Here은 두 프로젝트를 함께 추가 한 프로젝트입니다.

답변

2

TPKeyboardAvoidingScrollView.m에는 키보드를 숨길 때 호출되는 메서드 (keyboardWillHide :)가 있습니다. 이 방법에서는 scrollview의 내용 오프셋이 CGPointZero로 설정되므로 scrollview가 첫 번째보기 컨트롤러에 표시됩니다. 이것은 당신이 TPKeyboardAvoidingScrollView의 객체를 사용하여 다른 뷰에 영향을 줄 수 있다는 점에 유의 textfield-

- (void)keyboardDidShow:(NSNotification*)notification { 
    [self setScrollEnabled:NO]; 
    //existing code 
} 

- (void)keyboardWillHide:(NSNotification*)notification { 
    [self setScrollEnabled:YES]; 
    //existing code with modification of content offset 
} 

을 편집하는 동안

- (void)keyboardWillHide:(NSNotification*)notification { 
    _keyboardRect = CGRectZero; 
    _keyboardVisible = NO; 

    // Restore dimensions to prior size 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; 
    [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]]; 
    self.contentInset = _priorInset; 
    //self.contentOffset = CGPointZero;//Replacing this with below line 
    self.contentOffset = CGPointMake(self.contentOffset.x, 0); 
    [self setScrollIndicatorInsets:self.contentInset]; 
    _priorInsetSaved = NO; 
    [UIView commitAnimations]; 
} 

스크롤을 중지하십시오.

+0

감사합니다. 키보드가 튀어 나올 때 좌우로 스 와이프 할 수있는 방법을 어떻게 중지시킬 수 있습니까? – Shinonuma

+1

편집 중에 스크롤하는 것을 방지하기위한 답변이 업데이트되었습니다. –

관련 문제