0

当键盘弹出时,我很难找出让我的 uitextfields 不被隐藏的最佳方法。现在我有一个 UIView 包含一个 uitableview 子视图和按钮。

* uiview里面的tableview其实是一个uiviewcontroller,带有一个程序化创建的tableivew,所以它不受uitableviewcontroller控制。

我已经完成了研究,我认为我需要一个滚动视图,然后将视图添加到滚动视图中,并在选择特定文本字段并通过键盘向上滚动时进行一些滚动。

这是一个好方法吗?

更新:

我有两个单独的视图控制器。例如,假设 MainViewcontroller 和 SecondViewcontroller。secondviewcontroller 中有一个 uitableview。表格视图内的单元格具有存储用户信息的文本框(如表单)。然后我所做的是在 mainviewcontroller 内部创建了一个 secondviewcontroller 对象。我这样做是因为我需要在视图底部有一个“下一个按钮”。当我选择一个字段时,它将位于键盘下方,当它弹出时,我想让它向上滚动,关闭时它会向下滚动。我不得不使用 uitableview 的对象,因为 Mainviewcontroller 类会很大。(如果我错了,请纠正我)。谢谢回复。

这是我正在尝试做的截图......完整的 UIView:http ://postimage.org/image/puzdwpj3t/ 键盘打开:http ://postimage.org/image/g5nkwzwpd/

//这里是一些代码: 1.这里的第一个类例如是SecondViewcontroller。2. 第二段代码比如mainviewcontroller,它创建了一个secondviewcontroller的对象。

  1. 下面的 uiviewcontroller 将创建一个包含 3 个部分的表。每个单元格都有一个文本字段(除了中间,它是一个拉起 uipickerview 的按钮)。这不是一个完整的课程,我只学习了创建表格的区域。

    -(void)viewDidLoad{
    [super viewDidLoad];
    
    
    
    
    //    scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
    //    scrollview.pagingEnabled = YES;
    //    
    //    //[scrollview addSubview:self.view];
    //    [self.view addSubview:scrollview];
    
    
    
    table.scrollEnabled = YES;
    dataArray = [[NSMutableArray alloc] init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 30)];
    
    //dropper
    titleField = [[UITextField alloc] initWithFrame:CGRectMake(10, 2, 300, 30)];
    titleField.layer.cornerRadius = 8;
    titleField.backgroundColor = [UIColor clearColor];
    
    NSArray *firstItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2", nil];
    
    NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:@"data"];
    [dataArray addObject:firstItemsArrayDict];
    
    
    //Second section dat
    NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:@"1", nil];
    NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:@"data"];
    [dataArray addObject:secondItemsArrayDict];
    
    
    NSArray *thirdItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
    NSDictionary *thirdItemsArrayDict = [NSDictionary dictionaryWithObject:thirdItemsArray forKey:@"data"];
    [dataArray addObject:thirdItemsArrayDict];
    
    NSLog(@"the dataArray%@",dataArray);
    
    
    if([self connectedToNetwork]){
    
    dispatch_async(kBgQueue, ^{
    
    //build the url of strings
    FULLURL = [SERVERNAME stringByAppendingFormat:TitleLink];
    //create the url
    NSURL *url = [[NSURL alloc] initWithString:FULLURL];
    //NSLog(@"here title url%@",url);
    
    //get the data from the url
    NSData* data = [NSData dataWithContentsOfURL: url];
    //NSLog(@"here%@",data);
    
    //get the data from the url
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    // NSLog(@"titleid:%@",TITLEID);
    // NSLog(@"title categories:%@",titlecategories);
    
    });
    
    [table setBounces:NO];
    
    
    }else{
    
    
    dispatch_async(dispatch_get_main_queue(), ^ {
    UIAlertView *alert = [[UIAlertView alloc]
          initWithTitle: @"Please Check your internet connection"
          message:@"Enable your internet connection"
          delegate: nil
          cancelButtonTitle:@"OK"
          otherButtonTitles:nil];
    [alert show];
    });
    }
    
    }
    
    -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
    {
    return [dataArray count];
    }
    
    
    -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
    {
    //Number of rows it should expect should be based on the section
    NSDictionary *dictionary = [dataArray objectAtIndex:section];
    NSArray *array = [dictionary objectForKey:@"data"];
    return [array count];
    
    }
    
    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.section == 1){
    cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"longdropper300.png"]];
    
    }
    else{
    cell.backgroundColor = [UIColor whiteColor];
    }
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, 290, 30)];
    
    
    static NSString *cellValue = @"Cell";
    UITableViewCell *cell =nil;
    
    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellValue];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    
    if ([indexPath section] == 0) {
    
    //cellValue=[items objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    //textField.tag = 1;
    textField.adjustsFontSizeToFitWidth = YES;
    textField.textColor = [UIColor blackColor];
    
    if(indexPath.section == 0){
    //textfield for email
    if ([indexPath row] == 0) {
    textField.tag = 1;
    textField.text = EMAIL;
    textField.textColor= [UIColor blackColor];
    textField.placeholder = @"Email: example@gmail.com";
    textField.keyboardType = UIKeyboardTypeEmailAddress;
    textField.returnKeyType = UIReturnKeyNext;
    
    }
    //textfield for phone number
    else {
    textField.tag = 2;
    if ([PHONENUMBER isEqual: [NSNull null]] && PHONENUMBER == nil && PHONENUMBER == NULL && [PHONENUMBER isEqual: @""]){
    NSLog(@"phone is empty%@",PHONENUMBER);
    //[PHONENUMBER isEqual:@"frank"];
    
    }else{
    NSLog(@"phone is not empty%@",PHONENUMBER);
    textField.text = PHONENUMBER;
    }
    
    textField.placeholder = @"Phone: xxx-xxx-xxxx";
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.secureTextEntry = NO;
    }
    textField.backgroundColor = [UIColor whiteColor];
    textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    textField.textAlignment = UITextAlignmentLeft;
    textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [textField setEnabled: YES];
    textField.delegate = self;
    [cell addSubview:textField];
    
    }
    }
    if(indexPath.section == 1){
    
    [titleField setTextColor:[UIColor whiteColor]];
    titleField.tag = 3;
    titleField.placeholder = @"Select Contact Title";
    titleField.returnKeyType = UIReturnKeyNext;
    
    //titleField == textField.tag = 3;
    if ([TITLENAME isEqual: [NSNull null]]){
    NSLog(@"titlename is empty%@",TITLENAME);
    
    }else{
    NSLog(@"titlename is not empty%@",TITLENAME);
    titleField.text = TITLENAME;
    }
    
    
    titleField.keyboardType = UIKeyboardTypeDefault;
    titleField.returnKeyType = UIReturnKeyDone;
    titleField.secureTextEntry = NO;
    titleField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    titleField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    titleField.textAlignment = UITextAlignmentCenter;
    titleField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [titleField setEnabled: NO];
    titleField.delegate = self;
    
    [cell addSubview:titleField];
    
    
    NSLog(@"here is the titlename%@",TITLENAME);
    
    }
    
    if(indexPath.section == 2){
    
    if ([indexPath row] == 0) {
    
    textField.tag = 4;
    textField.placeholder = @"First Name";
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    
    if ([FIRSTNAME isEqual: [NSNull null]]){
    NSLog(@"firstname is empty%@",FIRSTNAME);
    textField.text = @"";
    
    }else{
    
    textField.text = FIRSTNAME;
    
    }
    
    textField.keyboardType = UIKeyboardTypeEmailAddress;
    textField.returnKeyType = UIReturnKeyNext;
    }
    
    if([indexPath row] == 1){
    textField.tag = 5;
    textField.placeholder = @"Last Name";
    
    
    if ([LASTNAME isEqual: [NSNull null]]){
    NSLog(@"lastname is empty%@",LASTNAME);
    textField.text = @"";
    
    }else{
    textField.text = LASTNAME;
    
    
    }
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyNext;
    //textField.secureTextEntry = NO;
    
    }
    
    if([indexPath row] == 2){
    
    textField.tag = 6;
    textField.placeholder = @"Company";
    
    if ([COMPANY isEqual: [NSNull null]]){
    NSLog(@"company is empty%@",COMPANY);
    textField.text = @"";
    }
    else{
    textField.text = COMPANY;
    }
    
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.secureTextEntry = NO;
    
    
    }
    
    //]textField.backgroundColor = [UIColor whiteColor];
    textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    textField.textAlignment = UITextAlignmentLeft;
    textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [textField setEnabled: YES];
    textField.delegate = self;
    [cell addSubview:textField];
    
    }
    
    return cell;
    }
    
    //Change the Height of title cell drop down
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
    {
    if (indexPath.section == 1) {
    if (indexPath.row == 0) {
    return 30;
    }
    }
    return 45;
    }
    
    
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    if(([textField tag] == 1)){
    
    NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    //Valid email address
    
    if ([emailTest evaluateWithObject:textField.text] == YES)
    {
    
    EMAIL = [textField.text copy];
    NSLog(@"here is the email%@",EMAIL);
    }
    else
    {
    
    UIAlertView *alert = [[UIAlertView alloc]
    
                  initWithTitle: @"Bad Email"
                  message: @"Please Re-enter the email address with a valid email"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    textField.text =  nil;
    NSLog(@"email not in proper format");
    }
    
    }
    
    if(([textField tag] == 2)){
    
    NSString *phoneRegex = @"[235689][0-9]{6}([0-9]{3})?";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    //valid email address
    
    if ([phoneTest evaluateWithObject:textField.text] == YES)
    {
    
    PHONENUMBER = [textField.text copy];
    NSLog(@"here is the phone number %@",PHONENUMBER);
    }
    else
    {
    NSLog(@"Phone Number Invalid");
    UIAlertView *alert = [[UIAlertView alloc]
                  initWithTitle: @"xxx-xxx-xxxx"
                  message: @"Please enter a valid phone number"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    textField.text =  nil;
    }
    }
    
    if(([textField tag] == 4)){
    
    
    FIRSTNAME = [textField.text copy];
    NSLog(@"here is the firstName%@",FIRSTNAME);
    }
    if(([textField tag] == 5)){
    
    
    LASTNAME = [textField.text copy];
    NSLog(@"here is the Last Name%@",LASTNAME);
    }
    
    if(([textField tag] == 6)){
    
    COMPANY = [textField.text copy];
    NSLog(@"here is the Company%@",COMPANY);
    }
    
    
    
    
    return YES;
    }
    
    -(BOOL)textFieldShouldReturn:(UITextField*)textField;
    {
    NSInteger nextTag = textField.tag + 1;
    // Try to find next responder
    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
    if (nextResponder) {
    
    // Found next responder, so set it.
    [nextResponder becomeFirstResponder];
    } else {
    // Not found, so remove keyboard.
    [textField resignFirstResponder];
    }
    return NO; // We do not want UITextField to insert line-breaks.
    }
    
  2. 主视图控制器 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // 自定义初始化 } return self; }

    - (void)addMyButton{    // Method for creating button, with background image and other properties
    
    loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    loginButton.frame = CGRectMake(10.0,130.0, 300.0, 40.0);
    [loginButton setTitle:@"Login" forState:UIControlStateNormal];
    loginButton.backgroundColor = [UIColor clearColor];
    [loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
    UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
    UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [loginButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
    UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
    UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [loginButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
    [self.view addSubview:loginButton];
    [loginButton addTarget: self
    action: @selector(loginButtonClicked:)
    forControlEvents: UIControlEventTouchUpInside];
    }
    
    //Change the View and send the information to the servlet once login is clicked.
    - (void)loginButtonClicked: (id)sender{
    
    loginButton.enabled = NO;
    activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 60, 20, 20)];
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    [self navigationItem].rightBarButtonItem = barButton;
    [activityIndicator startAnimating];
    
    [passwordTF resignFirstResponder];
    
    
    
    //start new thread
    //dispatch_async(kBgQueue, ^{
    NSLog(@"Username:%@",USERNAME);
    NSLog(@"Password:%@",PASSWORD);
    NSLog(@"COMPANYID: %@", COMPANYID);
    //NSLog(@"LOGINID: %@", LOGINID);
    
    if((USERNAME == NULL) || (USERNAME == nil) || ([USERNAME isEqualToString:@""])){
    //NSLog(@"null password or usernaem");
    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle: @"Username or password not found"
              message:@"please try again"
              delegate: nil
              cancelButtonTitle:@"OK"
              otherButtonTitles:nil];
    [alert show];
    [activityIndicator stopAnimating];
    
    // MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    // [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    }else if((PASSWORD == NULL) || (PASSWORD == nil) || ([PASSWORD isEqualToString:@""])){
    //NSLog(@"null password or usernaem");
    
    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle: @"Username or password not found"
              message:@"please try again"
              delegate: nil
              cancelButtonTitle:@"OK"
              otherButtonTitles:nil];
    [alert show];
    [activityIndicator stopAnimating];
    
    // MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    // [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    }else{
    //NSLog(@"all good");
    
    NSLog(@"Login button clicked, load the next view and check for password");
    NSLog(@"full the url%@",FULLURL);
    //build the url of strings
    FULLURL = ******
    
    
    if([self connectedToNetwork])
    
    {
    dispatch_queue_t downloadQueue = dispatch_queue_create("data loader", NULL);
    
    dispatch_async(downloadQueue, ^{
    
    //create the url
    NSURL *url = [[NSURL alloc] initWithString:FULLURL];
    NSLog(@"here%@",url);
    
    //get the data from the url
    NSData* data = [NSData dataWithContentsOfURL: url];
    NSLog(@"here%@",data);
    
    NSLog(@"here that data%@",data);
    
    if(data != nil){
    //
    //get the data from the url
    
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    //
    NSLog(@"hello Username:%@",USERNAME);
    NSLog(@"Password:%@",PASSWORD);
    NSLog(@"h4llo COMPANYID: %@", COMPANYID);
    NSLog(@"LOGINID: %@", LOGINID);
    
    //
    //       // [self performSelectorOnMainThread:@selector(checkLogin:) withObject:LOGINID waitUntilDone:YES];
    //
    //
    @try {
    //NSLog(@"before loginddd %@",LOGINID);
    if(COMPANYID != 0){
    
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        [prefs setObject:USERNAME forKey:@"UserName"];
        [prefs setObject:@"Pass" forKey:@"Pass"];
        // This is suggested to synch prefs, but is not needed
        [prefs synchronize];
    
        NSLog(@"here is the login identiy%@",LOGINID);
        MangoContactSelection *SenderInfoViews = [[MangoContactSelection alloc] init];
        [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    
    
    }
    else{
        dispatch_async(dispatch_get_main_queue(), ^ {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"bad NAME"
                              message:@"GOO"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
    
    //                        [self.view setNeedsDisplay];
        [self.view reloadInputViews];
        MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
        [self.navigationController pushViewController:SenderInfoViews animated:NO];
            [activityIndicator stopAnimating];
        });
    }
    }
    @catch (NSException * e) {
    NSLog(@"Exception: %@", e);
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Login Failed"
                          message:@"Bad"
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
    //[activityIndicator stopAnimating];
    }
    
    // if the data is nil do this
    }else{
    dispatch_async(dispatch_get_main_queue(), ^ {
    UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: @"No Internet!"
                      message:@"Please Check your internet Connection"
                      delegate: nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil];
    [alert show];
    [self.view setNeedsDisplay];
    MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    [self.navigationController pushViewController:SenderInfoViews animated:NO];
    });
    }
    
    dispatch_async(dispatch_get_main_queue(), ^ {
    
    //UIImage *image = [UIImage imageWithData:imageData];
    
    //[table reloadData];
    //[actIndicator stopAnimating];
    [self.view reloadInputViews];
    [activityIndicator stopAnimating];
    
    // sender because that's the element that called us by clicking refresh
    
    });
    
    });
    
    
    }else{
    
    UIAlertView *alert = [[UIAlertView alloc]
                  initWithTitle: @"No Internet!"
                  message:@"Please Check your internet Connection"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    [self.view setNeedsDisplay];
    MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    [self.navigationController pushViewController:SenderInfoViews animated:NO];
    }
    }
    [self.view reloadInputViews];
    }//login
    
    -(void)gobacktoContactCreate{
    MangoContactSelection *gobackhome = [[MangoContactSelection alloc]init];
    [self.navigationController pushViewController:gobackhome animated:YES];
    
    }
    
    - (void)viewDidLoad
    {
    
    [super viewDidLoad];
    //self.view setBackgroundColor:([UIColor blackColor]);
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *userName = [prefs stringForKey:@"UserName"];
    //NSString *pass = [prefs stringForKey:@"Pass"];
    
    //navigation bar
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    [self.navigationController setNavigationBarHidden: NO animated:NO];
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:@selector(gobacktoContactCreate)];
    
    self.navigationItem.title=@"Login";
    
    //User name text field................
    usernameTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 25, 300, 40)];
    usernameTF.borderStyle = UITextBorderStyleRoundedRect;
    usernameTF.font = [UIFont systemFontOfSize:15];
    usernameTF.placeholder = @"Username";
    usernameTF.text = userName;
    usernameTF.autocorrectionType = UITextAutocorrectionTypeNo;
    usernameTF.keyboardType = UIKeyboardTypeDefault;
    usernameTF.returnKeyType = UIReturnKeyNext;
    usernameTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    usernameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
    
    
    //User name text field................
    passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 75, 300, 40)];
    passwordTF.borderStyle = UITextBorderStyleRoundedRect;
    passwordTF.font = [UIFont systemFontOfSize:15];
    passwordTF.placeholder = @"Password";
    passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
    passwordTF.keyboardType = UIKeyboardTypeDefault;
    passwordTF.returnKeyType = UIReturnKeyDone;
    passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    passwordTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    passwordTF.secureTextEntry = YES;
    
    //create the clickable labels
    //register link
    registerLabel = [[UILabel alloc]initWithFrame:CGRectMake(150,170, 150, 20)];
    registerLabel.text = @"Request an account";
    registerLabel.font = [UIFont systemFontOfSize:12];
    registerLabel.userInteractionEnabled = YES;
    registerLabel.textColor = [UIColor blueColor];
    UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestRegistration:)];
    [registerLabel addGestureRecognizer:gr];
    gr.numberOfTapsRequired = 1;
    gr.cancelsTouchesInView = NO;
    
    //create the label for
    registerText = [[UILabel alloc]initWithFrame:CGRectMake(60,170, 90, 20)];
    registerText.text = @"New to *******?";
    registerText.font = [UIFont systemFontOfSize:12];
    
    //    //forgot password link
    //    forgotPassword = [[UILabel alloc]initWithFrame:CGRectMake(210,190, 150, 20)];
    //    forgotPassword.font = [UIFont systemFontOfSize:12];
    //    forgotPassword.textColor = [UIColor blueColor];
    //    forgotPassword.text = @"Forgot Password?";
    //    forgotPassword.userInteractionEnabled = YES;
    //    UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestForgottenPassword:)];
    //    [registerLabel addGestureRecognizer:tapRec];
    //    tapRec.numberOfTapsRequired = 1;
    //    tapRec.cancelsTouchesInView = NO;
    
    [self.view addSubview:passwordTF];
    [self.view addSubview:usernameTF];
    [self.view addSubview:registerLabel];
    [self.view addSubview:registerText];
    
    //    [self.view addSubview:forgotPassword];
    
    [self addMyButton];
    
    usernameTF.delegate = self;
    passwordTF.delegate = self;
    
    }
    
    -(void)requestRegistration:(UITapGestureRecognizer *)gr{
    
    //for registration
    NSLog(@"request registration link clicked");
    
    }
    
    
    -(void)requestNewPassword:(UITapGestureRecognizer *)tapRec{
    
    //for registration
    NSLog(@"request password link clicked");
    }
    
    
    
    //Grabs the Json from the servlet and then parses it for the username and password.
    
    - (void)fetchedData:(NSData *)responseData {
    //parse out the json data
    
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
                                         options:kNilOptions
                                           error:&error];
    
    //NSLog(@"here is the login info from json: %@", json);
    // NSString *FALSELOGIN;
    
    
    COMPANYID = [json valueForKey:@"companyid"];
    NSLog(@"COMPANY ID: %@", COMPANYID);
    
    // LOGINID = [json valueForKey:@"login"];
    // NSLog(@"LOGIN ID: %@", LOGINID);
    
    }
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    if((textField = usernameTF)){
    USERNAME = [textField.text copy];
    //NSLog(@"here is the string for username;%@", USERNAME);
    }
    
    if((textField = passwordTF)){
    PASSWORD = [textField.text copy];
    
    //NSLog(@"here is the password guy %@",PASSWORD);
    
    }
    
    return YES;
    }
    
    
    
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
    if (textField == usernameTF) {
    [passwordTF becomeFirstResponder];
    }
    else{
    [passwordTF resignFirstResponder];
    }
    return YES;
    }
    
    
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    [passwordTF resignFirstResponder];
    //
    //}
    
    - (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
    
    @end
    
4

2 回答 2

0

Dhaval,我相信你的解决方案会奏效,但我最终在这里找到了我想要的东西:

http://www.youtube.com/watch?feature=player_detailpage&v=qSvDWnasJ9I

谢谢。

于 2013-03-15T14:40:59.180 回答
0

您已经在 UIViewController 的视图中添加了 Tableview。正确的?

您在哪个视图中添加了 UITextview。?UIViewController 的视图??

您可以在 UIView 中添加 UITextView,并通过应用动画来更改 UITextView 的框架。

前任。

// 向上查看....

[UIView animationWithDuration:secs delay:0.0 option:option animation:^{

    CGRect frame = textview.frame;
    frame.origin.y = 10; // Change Y position of frame.
    textview.frame = frame;

}
completion:nil];

// 关闭视图

[UIView animationWithDuration:secs delay:0.0 option:option animation:^{

    CGRect frame = textview.frame;
    frame.origin.y = 100; // Change Y position of frame.
    textview.frame = frame;

}
completion:nil];

无需使用 UIScrollView。

于 2013-03-06T18:32:36.733 回答