簡體   English   中英

iPhone:在 UITextField 之間切換時 UIScrollView 出現問題

[英]iPhone : Problems with UIScrollView when switching between UITextFields

我有 15 個文本字段在同一個視圖上。

現在,隨着鍵盤的出現,我調整了滾動視圖的大小,以使視圖下部的文本字段可見。

我觀察到從一個 textField 切換到另一個會將 scrollView 帶到其原始框架。

每次我從 textField 中退出第一響應者時,如何避免我的滾動視圖的框架重置?

         // Here I am resetting the scrollView size so the textField do not hide behind the keyboard.

       - (void)textFieldDidBeginEditing:(UITextField *)textField
          {
          [scroll setFrame:CGRectMake(503, 123, 515, 275)]; 
          [scroll setContentSize:CGSizeMake(515, 550)];  
          }

         // Here I am resizing the scrollView so after returning the keyboard the scrollView gets its original hight
      - (void)textFieldDidEndEditing:(UITextField *)textField
        {
      [scroll setFrame:CGRectMake(503, 123, 515, 570)]; 
         [scroll setContentSize:CGSizeMake(515, 560)]; 
        }

為什么每次都改變scrollView的內容大小?

[scroll setContentSize:CGSizeMake(515, 560)];

最好有一個固定的contentSize並根據textField更改scrollViewcontentOffset

我認為你對contentSize的工作方式感到困惑——如果你的滾動視圖的內容沒有改變(當你顯示鍵盤時文本字段沒有被刪除),那么你不應該改變 contentSize。 正如您所做的那樣,設置frame應該就足夠了。

暫無
暫無

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

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