我在键盘显示事件后遇到UIScrollview问题,显然我的UITextField就像这样向上移动:
http://i.stack.imgur.com/ccBSp.png
这是在键盘显示后:
http://i.stack.imgur.com/X6NU2.png
我完全按照例子做了,这是我的代码:
-(void) keyboardDidShow: (NSNotification *)notif {
if (keyboardVisible) {
NSLog(@"Keyboard is already visible. Ignoring notofication.");
return;
}
//The keyboard wasn't visible before
NSLog(@"Resizing smaller for keyboard");
// Get the size of the keyboard.
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
// Resize the scroll view to make room for the keyboard
CGRect viewFrame = self.view.frame;
viewFrame.size.height -= keyboardSize.height;
scrollView.frame = viewFrame;
keyboardVisible = YES;}
-(void) keyboardDidHide: (NSNotification *)notif {
if (!keyboardVisible) {
NSLog(@"Keyboard is already hidden. Ignoring notification.");
return;
}
// The keyboard was visible
NSLog (@"Resizing bigger with no keyboard");
//Get the size of the keyboard.
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
// Reset the height of the scroll view to its original value
CGRect viewFrame = self.view.frame;
viewFrame.size.height += keyboardSize.height;
scrollView.frame = viewFrame;
keyboardVisible = NO;}
答案 0 :(得分:0)
您是否尝试过使用keyboardWasShown和keyboardWasHidden而不是WillShow和WillHide?另外,我注意到你正在使用“UIKeyboardBoundsUserInfoKey”进行Show&隐藏。试试“UIKeyboardFrameBeginUserInfoKey”& “UIKeyboardFrameEndUserInfoKey”