gpt4 book ai didi

iphone - becomeFirstResponder 重置 contentOffset

转载 作者:可可西里 更新时间:2023-11-01 03:57:25 26 4
gpt4 key购买 nike

我有一个 UIScrollView,其中有一个 UITextField,所以我所做的是在第三个文本字段(密码)上向下滚动 UIScrollView 的偏移量:

#pragma mark UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if ((textField == self.emailTextField_ || textField == self.passwordTextField_)){
if (self.scrollView_.contentOffset.y != self.emailTextField_.frameY - self.emailTextField_.frameHeight/2){
shouldAdjustOffset = YES;
} else {
shouldAdjustOffset = NO;
}

if (shouldAdjustOffset){
[self.scrollView_ setContentOffset:CGPointMake(0, self.emailTextField_.frameY - self.emailTextField_.frameHeight/2) animated:YES];
}
}
}

-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.firstNameTexField_){
[self.firstNameTexField_ resignFirstResponder];
[self.lastNameTextField_ becomeFirstResponder];
} else if (textField == self.lastNameTextField_){
[self.lastNameTextField_ resignFirstResponder];
[self.emailTextField_ becomeFirstResponder];
} else if (textField == self.emailTextField_){
[self.emailTextField_ resignFirstResponder];
[self.passwordTextField_ becomeFirstResponder];
} else if (textField == self.passwordTextField_){
[self signupButtonPressed:nil];
[self.passwordTextField_ resignFirstResponder];
}

return YES;
}

现在的问题是,当我在下一个文本字段上时,它会将内容偏移量重置回 0,当我这样做时:

 [self.emailTextField_ resignFirstResponder];
[self.passwordTextField_ becomeFirstResponder];

.我怎样才能防止这种情况发生?

最佳答案

只需在显示键盘之前关闭 scrollview 滚动(成为 FirstResponder)并启用它之后的滚动,

scrollView.scrollEnabled = NO;
[someControl becomeFirstResponder];
scrollView.scrollEnabled = YES;
[scrollview doTheScrollingHere];

关于iphone - becomeFirstResponder 重置 contentOffset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12809119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com