簡體   English   中英

UITable中的TextField在鍵盤上滾動

[英]TextField in UITable Scroll on KeyBoard

我在UITableViewUITextField ,當我單擊UITextField我已經移動了偏移量,但是我的問題是,當用戶滾動到下一個字段時,它會顯示奇怪的行為,有時輸入刷新或焦點將返回到先前的UITextField

請參閱此代碼並根據您的項目實施

  • (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    [self scrollViewToCenterOfScreen:textField];
    返回是; }

  • (void)scrollViewToCenterOfScreen:(UIView *)theView {
    CGFloat viewCenterY = theView.center.y;
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

    CGFloat availableHeight = applicationFrame.size.height-200; //刪除鍵盤覆蓋的區域

    CGFloat y = viewCenterY-availableHeight / 2.0;
    如果(y <0){
    y = 0;
    }
    [scrollview setContentOffset:CGPointMake(0,y)animation:YES];

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField {

if ([textField isEqual:txtStAppField])
{
    [txtStConfirmField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
    [txtDummyAppField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
    [txtDummyConfirmFeild becomeFirstResponder];
}
else 
{
    [textField resignFirstResponder];       
    [scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

return YES;

}

// txtStConfirmField,txtDummyConfirmFeild,txtDummyAppField,txtStConfirmField,txtStConfirmField是tectField名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM