2013-10-17 57 views
0

我在iPhone屏幕上垂直排列了許多文本字段。每個字段都調用鍵盤。如何在屏幕上實現帶有許多文本字段的NSScrollView?

問題在於屏幕底部的字段,因爲鍵盤會彈出並覆蓋它們,所以用戶看不到它們。

我已經添加UIScrollView並拖動它上面的所有文本字段 - 但滾動不起作用。 我應該添加一些代碼嗎?

如何實現滾動視圖?

+0

看看一個[此頁](https://開頭開發商。 apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html) – HAS

+0

http://www.codeproject.com/Articles/46556/How-To-Use-UIScrollView-in-Your-iPhone -App看看這個鏈接 – square

回答

0

添加代理的所有文本框,並使用下面的代碼按照您的要求 這裏self.scrMain是我的滾動視圖對象

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if (textField == txtRegNo) { 
     [self.scrMain setContentOffset:CGPointMake(0, 20) animated:YES]; 
    } 
    if (textField == txtName) { 
     [self.scrMain setContentOffset:CGPointMake(0, 80) animated:YES]; 
    } 
    if (textField == txtMobile) { 
     [self.scrMain setContentOffset:CGPointMake(0, 150) animated:YES]; 
    } 
    return YES; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [self.scrMain setContentOffset:CGPointMake(0, 0) animated:YES]; 
    [textField resignFirstResponder]; 
    return YES; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [self.scrMain setContentOffset:CGPointMake(0, 0) animated:YES]; 
    [textField resignFirstResponder]; 
}