<pre>
-
(void)registerNotification
{
[super registerNotification];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
} -
(void)deregisterNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
[super deregisterNotification];
} -
(void)handleKeyboardWillShowNotification:(NSNotification)noti
{
CGFloat tmpKeyboardVisibleHeight = 0;
CGRect endRect = [(NSValue)noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
tmpKeyboardVisibleHeight = self.view.height - endRect.origin.y;
if (tmpKeyboardVisibleHeight != currentKeyboardVisibleHeight)
{
currentKeyboardVisibleHeight = tmpKeyboardVisibleHeight;
[self scollContentContainer:currentKeyboardVisibleHeight];
}
} -
(void)handleKeyboardWillChangeFrameNotification:(NSNotification)noti
{
//如果currentKeyboardVisibleHeight为0则代表键盘将会被隐藏,否则则会被显示出来
CGRect endRect = [(NSValue)noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//不能判断beginRect和endRect是否相等,如果在不相等的时候才做�更新,程序会出现bug
CGFloat tmpKeyboardVisibleHeight = 0;
tmpKeyboardVisibleHeight = self.view.height - endRect.origin.y;
if (tmpKeyboardVisibleHeight != currentKeyboardVisibleHeight)
{
currentKeyboardVisibleHeight = tmpKeyboardVisibleHeight;
//如果密码框可以切换输入法,这儿可能会有潜在的bug
[self scollContentContainer:currentKeyboardVisibleHeight];
}
}
</pre>
网友评论