UITextField: move view when keyboard appears

后端 未结 7 1269
心在旅途
心在旅途 2020-11-29 16:32

I\'m currently working on an iPhone application with a single view, which has multiple UITextFields for input. When the keyboard shows, it overlays the bottom textfields. So

相关标签:
7条回答
  • I got your Problem just do simple thing just give outlet to UIScrollview. set unique Tag property for each textfield in view.

    -(void)textFieldDidBeginEditing:(UITextField *)textField
        {   
            switch (textField.tag)
            {
                case 2:    //can be your textfiled tag
                  { CGPoint scrollPoint = CGPointMake(0, yourtextfield.frame.origin.y-150); 
                                               //set figure y-150 as per your comfirt
                      [scrollview setContentOffset:scrollPoint animated:YES]; 
                 }break;
    
                  case 3:   
                  { CGPoint scrollPoint = CGPointMake(0, yourtextfield.frame.origin.y-180); 
                                               //set figure y-180 as per your comfirt
                      [scrollview setContentOffset:scrollPoint animated:YES]; 
                 }break;
    
                 ...
    
             }
        }
    
        -(void)textFieldDidEndEditing:(UITextField *)textField{
    
            if(textField.tag==3){
                [scrollview setContentOffset:CGPointZero animated:YES];
                    }
             //set the last textfield when you want to disappear keyboard.
        }
    
    0 讨论(0)
提交回复
热议问题