キーボード表示イベントの後に 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;}