2013-02-26 39 views
0

如何將此視圖包含在scrollerView中?爲子視圖實現scrollview iphone

我有一個不同的文本框的子視圖,我希望它在滾動視圖,以便當用戶點擊字段視圖滾動。

- (UIView *)Form 
{ 
    if (!_Form) { 

     CGRect frame = CGRectMake(0.0, Height, Width, 310.0); 
     UIView *container = [[UIView alloc] initWithFrame:frame]; 

     CGFloat y = 15.0; 
     frame = CGRectMake(15.0, y, width, height); 
     UITextField *field = [[UITextField alloc] initWithFrame:frame]; 
     [ 
     field.placeholder = @"text"; 


     CGFloat spacing = 8.0; 
     y = frame.origin.y + height + spacing; 
     frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text6"; 


     frame.size.height = 200.0; 

     y = frame.origin.y + height + space; 
     frame = CGRectMake(15.0, y, width - 2*15.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text1*"; 



     y = frame.origin.y + height + 16.0; 
     CGFloat w = (kDeviceWidth - 2 * 15.0)/2; 
     frame = CGRectMake(15.0, y, w - 2.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text3*"; 


     frame = CGRectMake(15.0 + w + 2.0, y, w - 2.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text4*"; 


     y = frame.origin.y + height + spacevalue; 
     frame = CGRectMake(15.0, y, w, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text5"; 



     y = frame.origin.y + height + 20.0; 
     frame = CGRectMake((frame.size.width - 192.0)/2, y, 192.0, 34.0); 



     y = frame.origin.y + height + 8.0; 
     frame = CGRectMake((frame.size.width - 192.0)/2, y, 192.0, 34.0); 
    } 
    return _Form; 
} 

你能用代碼幫我嗎。 感謝

回答

0

我有這樣的代碼:

CGPoint puntoInicial; 
-(void) textFieldDidBeginEditing:(UITextField *)textField { 
    CGPoint pt; 
    CGRect rc = [textField bounds]; 
    rc = [textField convertRect:rc toView:scrollView]; 
    pt = rc.origin; 
    puntoInicial = pt; 
    pt.x = 0; 
    pt.y -= 250; 
    [scrollView setContentOffset:pt animated:YES]; 
    textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters; 
} 

//Bajar la pantalla cuando se termina de editar 
-(void) textFieldDidEndEditing:(UITextField *)textField { 
    puntoInicial.x = 0; 
    puntoInicial.y = 0; 
    [scrollView setContentOffset:puntoInicial animated:YES]; 
} 

只有把這個在你的代碼,並在文本框 - >連接檢查 - > Oulets - >代表,把文件的所有者