동일한 문제가 있었지만 첫 번째 응답자로 설정하지 않고 자동 레이아웃 된 UITextEdit을보기로 스크롤하려고했습니다.
나에게있어서 UITextField의 경계는 자동 레이아웃 과정에서 나중에 설정되었으므로 레이아웃을 설정 한 직후에 경계를 설정하는 것은 아직 유효하지 않다.
해결 방법 나는 UITextField의 자손을 만들고 setBounds:
을 덮어 쓰고 "나중에"보기로 스크롤하는 0 타이머를 추가했습니다. 시스템의 자동 레이아웃 단계가 "나중에"스크롤 될 수 없기 때문에 스크롤 할 수 없습니다 필드 화면 키보드와 추가로 편집해야하는 경우
@interface MyTextField: UITextField
{
bool _scrollIntoView;
}
..
@end
@implementation MyTextField
-(void)setBounds:(CGRect)bounds
{
bool empty=CGRectIsEmpty(self.bounds);
bool isFirstResponder=self.isFirstResponder;
[super setBounds:bounds];
if (empty && !isFirstResponder && _scrollIntoView)
[self performSelector:@selector(scrollIntoViewLater) withObject:nil afterDelay:0];
else if (empty && isFirstResponder)
[self performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
}
-(void)scrollIntoViewLater
{
CGRect r=[scrollView convertRect:self.bounds fromView:self];
[scrollView scrollRectToVisible:r animated:TRUE];
}
@end
) 그 시점에서 완료, 단순히 나중에 becomeFirstResponder 전화 : 그것은 차례의 scrollRectToVisible:animated:
를 호출하는 개인 scrollTextFieldToVisible
API를 사용하여 키보드 위의보기에 자동적으로 스크롤 scrollview. 샘플 링크가 BTW 고장
...
출처
2017-10-28 13:18:18
Leo
TPKeyboardAvoidingScrollView이 문제를 해결하지만 난 줄 또는 두 개의 고칠 때 전체 타사 클래스를 사용하지 않습니다. –
답안에 편집본 하나를 추가했습니다. 그럴 가능성이 없는지 확인하십시오. – Bhavin