Ich möchte die Ansicht nach oben verschieben, wenn die Tastatur angezeigt wird, und nach unten, wenn die Tastatur wie in der Nachricht ausgeblendet ist. Ich bin in der Lage, es zu erreichen, aber ich verberge die Vorhersage, dass es etwas Leerstelle gibt. Verwalten der Ansichtsposition mit der UIKeyboard-Vorhersage ein und aus
Ich bin Umgang mit der Bewegung der Tastatur mit „UIKeyboardWillShowNotification“ und „UIKeyboardWillHideNotification“
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - keyboard movements
- (void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
self.view.frame = f;
}];
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.view.frame = f;
}];
}
Ich mag die Bewegung der Ansicht behandeln, wie es in den Nachrichten App passiert.
Es funktioniert gut bro? –