Ich versuche, die Höhe der iOS-Tastatur zu erreichen, so dass ich meine Ansicht verschieben kann, wenn die Tastatur animiert ist. Allerdings bekomme ich immer den Wert 258 zurück (was ist nicht korrekt, da es meine Sicht zu hoch treibt?) Warum passiert das? Code unten:Obj-c - Falsche Tastaturhöhe wird zurückgegeben?
ViewController.m
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)keyboardWillChange:(NSNotification *)notification {
NSDictionary* keyboardInfo = [notification userInfo];
NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
self.keyboardHeight = keyboardFrameBeginRect.size.height;
}
- (void) animateTextView:(BOOL) up
{
const int movementDistance = self.keyboardHeight;
const float movementDuration = 0.3f;
int movement= movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.upView.frame = CGRectOffset(self.upView.frame, 0, movement);
[UIView setAnimationDidStopSelector:@selector(afterAnimationStops)];
[UIView commitAnimations];
}
Noch gibt Höhe von 258 - ohne Würfel. – Brittany
Wo haben Sie diesen Wert protokolliert? Verwenden Sie 'UITabBarController'? – trungduc
Ja, die Ansicht ist in einen UITabBarController eingebettet. Ich protokolliere den Wert in animateTextView und in keyboardWillChange. – Brittany