2016-12-29 4 views
-2

textView이 키보드를 표시하거나 숨길 때 화면을 위아래로 움직이려면 위의 방법으로 초점을 맞출 때 마지막 필드를 볼 수 있습니다.키보드가 표시 될 때 탐색 표시 줄이 보이지 않음

- (void)textViewDidBeginEditing:(UITextView *)textField 
{ 
    [self animateTextView: textField up: YES]; 
} 


- (void)textViewDidEndEditing:(UITextView *)textField 
{ 
    [self animateTextView: textField up: NO]; 
} 

- (void) animateTextView: (UITextView*) textField up: (BOOL) up 
{ 
    const int movementDistance = 130; // tweak as needed 
    const float movementDuration = 0.2f; // tweak as needed 

    int movement = (up ? -movementDistance : movementDistance); 

    [UIView beginAnimations: @"anim" context: nil]; 
    [UIView setAnimationBeginsFromCurrentState: YES]; 
    [UIView setAnimationDuration: movementDuration]; 
    self.view.frame = CGRectOffset(self.view.frame, 0, movement); 
    [UIView commitAnimations]; 
} 

는 그러나 문제는 그것이 또한 화면이 위로 이동하면 이동 년대 navBar이 위치는 [self animateTextView: textField up: YES]; 사용 후의에서 navBarnavBar 제외한 모든 이동하거나 유지하는 방법이 있다는 것입니다?

+0

왜? 왜 이런 생각을하게 될까요? 왜 'UINavigationController'를 사용하지 않습니까? 왜 당신은'beginAnimations :'API를 사용하고 있습니까? 이것은 무엇입니까, iOS/iphoneos 3? –

답변

1

기본보기에 사용자 지정 NavigationBar가 있기 때문입니다. 스토리 보드에서 NavBar 아래에 다른 UIView를 만든 다음 textField 및 기타 UI 객체를이 새 뷰에 배치하십시오. 이것을 마음대로 유지하십시오. navBar가 키보드가 나타날 때 위쪽으로 밀고있는 UIView 객체와 같은면이되어서는 안됩니다. 그래서 이것의 콘센트를 새로 UIView 개체를 만들고 대신 viewController 그냥 주 모드로 이동이 새로 만든 된보기를 이동하십시오.

[UIView animateWithDuration:0.2 animations:^{ 
    //Just Replace Your Animation Code with This and see the difference. 
    self.containerViewOfOtherObjects.frame = CGRectOffset(self.containerViewOfOtherObjects.frame, 0, movement); 
}]; 
+0

감사합니다. Syed 씨, 제가 추가했습니다. 답변에 게시 된 'self.view.frame = CGRectOffset (self.view.frame, 0, movement);'행을 대체해야합니까? 또는'[UIView beginAnimations : @ "anim"context : nil]; "... – CGR

+0

번을 제거하면됩니다. 'self.view.frame = CGRectOffset (self.view.frame, 0, movement);' –

+0

시도했지만 시도가 정말 빠르게 움직여 새로운 추가보기가 원래 장소 – CGR

관련 문제