iOS键盘弹出通知后加入动画
首先我們要注冊鍵盤彈出和彈入的通知
[[NSNotificationCenter defaultCenter] addObserver:self
???????????????????????????????????????????? selector:@selector(keyboardWillShow:)
???????????????????????????????????????????????? name:UIKeyboardWillShowNotification
?????????????????????????????????????????????? object:nil];
?? ?
??? [[NSNotificationCenter defaultCenter] addObserver:self
???????????????????????????????????????????? selector:@selector(keyboardWillHide:)
???????????????????????????????????????????????? name:UIKeyboardWillHideNotification
?????????????????????????????????????????????? object:nil];
//Code from Brett Schumann
-(void) keyboardWillShow:(NSNotification *)note{??? // get keyboard size and loctaion
?? ?CGRect keyboardBounds;
??? [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
??? NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
??? NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
?? ?
??? // Need to translate the bounds to account for rotation.
??? keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
?? ?
?? ?// get a rect for the textView frame
?? ?CGRect btnFrame = self.editView.frame;
??? btnFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + btnFrame.size.height);
?? ?// animations settings
?? ?[UIView beginAnimations:nil context:NULL];
?? ?[UIView setAnimationBeginsFromCurrentState:YES];
??? [UIView setAnimationDuration:[duration doubleValue]];
??? [UIView setAnimationCurve:[curve intValue]];
??? [UIView setAnimationDelegate:self];
?? ?
?? ?// set views with new info
?? ?self.editView.frame = btnFrame;
??? // commit animations
?? ?[UIView commitAnimations];
?? ?
??? ???
?? ?
}
- (void) keyboardWillHide:(NSNotification *)note{
??? NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
??? NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
?? ?
?? ?// get a rect for the textView frame
?? ?CGRect btnFrame = self.editView.frame;
??? btnFrame.origin.y = self.view.bounds.size.height + btnFrame.size.height;
?? ?
?? ?// animations settings
?? ?[UIView beginAnimations:nil context:NULL];
?? ?[UIView setAnimationBeginsFromCurrentState:YES];
??? [UIView setAnimationDuration:[duration doubleValue]];
??? [UIView setAnimationCurve:[curve intValue]];
?? ?
?? ?// set views with new info
?? ?self.editView.frame = btnFrame;
?? ?
?? ?// commit animations
?? ?[UIView commitAnimations];
?? ?
?? }
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的iOS键盘弹出通知后加入动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10新建文件夹重命名卡死怎么办 新
- 下一篇: 电脑组装完毕之后点不亮怎么办 新电脑组装