2025-02-15

在viewdidload的時候,把每個TextField設好tag。之後就可以根據最下面的UITextField的內容來判斷鍵盤的彈出和關閉瞭

 有的TextField* name

name.tag = 2;

下面就是當tag==2的情況下,才能夠把界面談到上面去。

– (void)textFieldDidBeginEditing:(UITextField *)textField 

{ //當點觸textField內部,開始編輯都會調用這個方法。textField將成為first responder  

    if (textField.tag == 2) {

        NSTimeInterval animationDuration = 0.30f;     

        CGRect frame = self.view.frame; 

        frame.origin.y -=216; 

        frame.size.height +=216; 

        self.view.frame = frame; 

        [UIViewbeginAnimations:@"ResizeView"context:nil]; 

        [UIView setAnimationDuration:animationDuration]; 

        self.view.frame = frame;                 

        [UIViewcommitAnimations];

    }

                   

 

– (BOOL)textFieldShouldReturn:(UITextField *)textField  

{//當用戶按下ruturn,把焦點從textField移開那麼鍵盤就會消失瞭 

//    textField

    if (textField.tag == 2) {

        NSTimeInterval animationDuration = 0.30f; 

        CGRect frame = self.view.frame;     

        frame.origin.y +=216;       

        frame.size. height -=216;    

        self.view.frame = frame; 

        //self.view移回原位置   

        [UIViewbeginAnimations:@"ResizeView"context:nil]; 

        [UIView setAnimationDuration:animationDuration]; 

        self.view.frame = frame;           www.aiwalls.com      

        [UIViewcommitAnimations];

    }

    [textField resignFirstResponder];    

    returnYES;

}        

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *