1

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

1 に答える 1

0

WillShow と WillHide の代わりに、keyboardWasShown と keyboardWasHidden を使用してみましたか? また、表示と非表示の両方に「UIKeyboardBoundsUserInfoKey」を使用していることに気付きました。「UIKeyboardFrameBeginUserInfoKey」と「UIKeyboardFrameEndUserInfoKey」を試してください

于 2012-12-19T09:48:56.350 に答える