15 개의 텍스트 필드가있는 앱을 개발 중입니다. 그래서 UIScrollView를 사용하여 스크롤링을 가능하게 만들었습니다. 그러나 마지막 5 개의 텍스트 필드는 편집 할 텍스트 필드를 클릭 할 때 키보드 뒤에 숨어 있습니다. 편집 모드에있을 때 키보드 위의 텍스트 필드를 이동하는 방법은 무엇입니까? 다시 말하지만, 텍스트 필드는 UIScrollView에 있습니다. UIView가 아닙니다.키보드가 UIScrollView의 텍스트 필드를 숨기고 있습니다. 키보드에 따라 텍스트 필드를 이동하는 방법?
답변
scrollView에 contentSize 및 contentOffset을 적절히 설정해야합니다. 따라서 마지막 텍스트 상자가 (0,300)의 원점에있는 경우 contentSize가 CGSizeMake (0, 600) 정도가되도록 설정 한 다음 contentOffset을 (0, 250)으로 설정해야합니다.
코드를 알고 있을까요? 내 말은, 지금까지 CGSizeMake를 모두 시도했다. – dcprog
시도 TPKeyboardAvoidingScrollView.
이미 가지고있는 스크롤보기를 잡고 클래스가 TPKeyboardAvoidingScrollView
으로 변경되면 키보드가 팝업 될 때 크기와 오프셋이 조정되어 필드가 올바르게 표시됩니다.
복잡한 레이아웃 (많은 텍스트 필드 및 기타 구성 요소)이있는 경우 손으로 처리하는 것이 까다로울 수 있으므로이 방법을 사용하는 것이 좋습니다. 이 컨트롤은 매력처럼 작동하고 작동하는 것처럼 간단합니다!
당신은 당신의 scrollView
Y이 textFieldShouldBeginEditing:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == textField11 || textField == textField12 || textField == textField13 || textField == textField14 || textField == textField15)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
//set Y according to keyBoard height
[scrollView setFrame:CGRectMake(0.0,-220.0,320.0,460.0)];
[UIView commitAnimations];
}
}
에서 조정하고 그것이 당신이 키보드 여기
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[scrollView setFrame:CGRectMake(0.0,0.0,320.0,460.0)];
[UIView commitAnimations];
}
의 반환 키를 누를 때 scrollView
프레임을 설정 줄일 수는 몇 가지 예제 코드입니다 :
#define kOFFSET_FOR_KEYBOARD 80.0
-(void)keyboardWillShow {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:mailTf])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
CGRect rect = self.view.frame;
if (movedUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
- (void)viewWillAppear:(BOOL)animated
{
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- 1. 키보드가 텍스트 필드를 숨기기
- 2. 텍스트 필드를 선택하는 방법
- 3. 텍스트 필드를 만드는 방법
- 4. 텍스트 필드를 어떻게 비활성화합니까?
- 5. 텍스트 필드를
- 6. 텍스트 필드를 통해 이동
- 7. 안드로이드에있는 WebView의 텍스트 필드가 키보드에 의해 감춰져 있습니다.
- 8. 툴바에 텍스트 필드를 추가하는 방법
- 9. HTML에서 텍스트 필드를 동기화하는 방법
- 10. 내가 텍스트 필드를 클릭하면
- 11. 테이블에 텍스트 필드를 구현하는 방법
- 12. 필드를 텍스트 상자에 바인딩하는 방법
- 13. 코코아에서 텍스트 필드를 지우는 방법
- 14. NSMutableArray에 텍스트 필드를 추가하는 방법
- 15. 입력시 초점이 맞을 때 스크롤 뷰에서 텍스트 필드를 이동하는 방법
- 16. 텍스트 내용에 따라 플로팅 텍스트 필드를 표시하는 방법은 무엇입니까?
- 17. 화면에 키보드가있는 경우 텍스트 입력 필드를 위로 이동하는 방법
- 18. 텍스트 필드의 길에있는 키보드 위로보기를 이동하는 방법
- 19. 무대에서 텍스트 필드를 참조하십시오.
- 20. 비활성화 텍스트 필드를 동적으로
- 21. 텍스트 필드를 선택한 후 키보드가 나타나면 이상한 iOS5 글리치가 발생합니다.
- 22. 텍스트 상자에서 테이블의 필드를 표시
- 23. asp에서 동적 텍스트 필드를 플래시하는 텍스트 설정
- 24. ios app에서 텍스트 필드를 동적으로 채우는 방법
- 25. Settings.bundle에서 텍스트 필드를 오른쪽 맞춤으로 설정하는 방법
- 26. 사용자 정의 UITableView에서 텍스트 필드를 얻는 방법
- 27. 플래시 cs5의 텍스트 필드를 회전
- 28. cocos2d에 텍스트 필드를 추가 할 수 없습니다.
- 29. 다른 입력란에 따라 필드를 작성해야합니다.
- 30. 텍스트 필드를 선택 상자로 만들기
아무 것도 UIScrollView에 대해 작동하지 않습니다. 그 이유는 질문을 게시했습니다. [키보드가있을 때 UITextField를 위로 이동하는 방법]의 가능한 복제본 – dcprog
(http://stackoverflow.com/questions/1126726/how-to-make- a-uitextfield-move-up-when-keyboard-is-present) –