IOS開發2-ipad 隱藏鍵盤動畫,可用來實現去除擋住view的操做

// Call this method somewhere in your view controller setup code.

- (void)viewDidLoad

{

    [self registerForKeyboardNotifications];


    [super viewDidLoad];

}

- (void)registerForKeyboardNotifications

{
//先取消以前的觀察者
 [[NSNotificationCenter defaultCenter] removeObserver:self 

 name:UIKeyboardDidShowNotification 

   object:nil];

 [[NSNotificationCenter defaultCenter] removeObserver:self 

 name:UIKeyboardDidHideNotification 

   object:nil];

 

    [[NSNotificationCenter defaultCenter] addObserver:self

  selector:@selector(keyboardWasShown:)

  name:UIKeyboardDidShowNotification object:nil];

 
//註冊觀察者
    [[NSNotificationCenter defaultCenter] addObserver:self

  selector:@selector(keyboardWasHidden:)

  name:UIKeyboardDidHideNotification object:nil];

}

 

// Called when the UIKeyboardDidShowNotification is sent.

- (void)keyboardWasShown:(NSNotification*)aNotification

{

 

 //self.frame = CGRectMake(0, -90, 320, 480);

}

 

// Called when the UIKeyboardDidHideNotification is sent 點下ipad的隱藏鍵盤鍵觸發

- (void)keyboardWasHidden:(NSNotification*)aNotification

{

 

[userField resignFirstResponder];  //必須的

    [passwordTxt resignFirstResponder];

    [UIView beginAnimations:@"LoginViewController" context:nil];

    [UIView setAnimationDuration:0.5];

    self.view.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);

    [UIView commitAnimations];    

 

}
相關文章
相關標籤/搜索