2015-04-07 217 views
-1

我一直在關注this和一堆其他教程/博客等試圖讓我的視圖滾動時,用戶點擊「返回」,並在UITextField結束正在被鍵盤覆蓋,但沒有任何實際工作。scrollView.setContentOffset不會滾動視圖,根本就不會滾動視圖

我想知道我必須做什麼或失蹤是造成這種情況?

基本上是:

  • 用戶想要做一些應用程序:添加信用卡
  • 顯示,包含了所有的CC領域
  • 的UITextFields的1/2是由覆蓋一個UIView鍵盤
  • 當用戶到達那裏時滾動視圖。

什麼都沒有發生。檢測'被鍵盤覆蓋'的代碼正在被執行,但是:[self.scrollView setContentOffset:scrollPoint animated:YES]根本沒有任何效果。

想法?

顯示截圖:

代碼:相同的鏈接教程。那裏沒有新東西。

+0

你能顯示/發佈你的代碼嗎? –

+0

您是否在添加內容後設置了滾動視圖的contentSize? –

回答

0

試試這個,

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
[UIView animateWithDuration:0.25 animations:^{ 

    [yourTextField setFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y-keyboardHeight, yourTextField.frame.size.width, yourTextField.frame.size.height)]; 
    }]; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 

[UIView animateWithDuration:0.25 animations:^{ 
    [yourTextField setFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y+keyboardHeight, yourTextField.frame.size.width, yourTextField.frame.size.height)]; 
}]; 
} 
0

我做些什麼來避免文本框被覆蓋的鍵盤當用戶觸摸它的文本框動畫在屏幕的頂部開始通過鍵盤輸入內容並在完成後將其回放。我認爲它更優雅。也許這可能是你的替代解決方案。我做它用不同的號碼不同screensizes ......你可能需要調整它,當然......

所以聽的文本字段代表和

- (void)textFieldDidBeginEditing:(UITextField *)textField { 

你做

CGSize result = [[UIScreen mainScreen] bounds].size; 

     if(result.height == 480){ 

     ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];}); 
     } 

     if(result.height == 568){ 

      ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];}); 
     } 

     if(result.height == 667){ 

      ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -238; [self.view setFrame:frame]; [UIView commitAnimations];}); 
     } 

     if(result.height == 736){ 

      ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -251; [self.view setFrame:frame]; [UIView commitAnimations];}); 
     } 

- (void)textFieldDidEndEditing:(UITextField *)textField { 

你只是BA動畫ck

({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = 0; [self.view setFrame:frame]; [UIView commitAnimations];}); 
1

您是否檢查過contentSize屬性?

要使滾動視圖可滾動,內容必須大於顯示區域(通常是滾動視圖的邊界)。

您可以通過默認

除了明確設置contentSize財產是CGSizeZero,設置contentInset屬性來調整顯示區域的大小,實現這一目標(在這種情況下,你可以設置底值等於鍵盤高度)當鍵盤彈出時

+0

僅適用於iOS 8。 iOS 7沒有效果。謝謝。 – cbrulak