2014-11-30 2 views
0

Есть:UIToolbar + UITextField = Чат

@property (weak, nonatomic) IBOutlet UIToolbar *toolBar; 

[nc addObserver:self selector:@selector(notificationKeyboard:) name:UIKeyboardWillShowNotification object:nil]; 
[nc addObserver:self selector:@selector(notificationKeyboard:) name:UIKeyboardWillHideNotification object:nil]; 

И попробуйте это:

- (void)notificationKeyboard:(NSNotification *)notification { 

UIViewAnimationOptions keyboardCurve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; 
double keyboardDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 
CGRect keyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
keyboardRect = [self.view convertRect:keyboardRect fromView:nil]; 
CGFloat pointY = CGRectGetMinY(keyboardRect); 

void (^animations)(void) = ^{ 

    CGRect toolBarRect = self.toolBar.frame; 
    toolBarRect.origin.y = pointY - CGRectGetHeight(toolBarRect); 
    self.toolBar.frame = toolBarRect; 

}; 

[UIView animateWithDuration:keyboardDuration 
         delay:0 
        options:keyboardCurve 
       animations:animations 
       completion:nil]; 
} 

Но нет анимации на мой взгляд :(

Некоторые detalės: - в раскадровке 1 панели с Ограничения Пробел (слева, справа, кнопка)

ответ

1

Вы не можете анимировать рамку просмотра, если вы nfigured этот вид с использованием автоматической компоновки. Вместо этого вам нужно выявить ограничения, которые вам нужно изменить (в вашем случае bottom, я думаю) и изменить значение для этого ограничения.

0

Мое решение:

void (^animations)(void) = ^{ 

    CGRect toolBarRect = self.toolBar.frame; 
    toolBarRect.origin.y = pointY - CGRectGetHeight(toolBarRect); 

    for(NSLayoutConstraint *constraint in self.view.constraints) { 
     if(constraint.secondAttribute == NSLayoutAttributeBottom && constraint.secondItem == self.toolBar) { 
      constraint.constant = CGRectGetHeight(self.view.frame) - pointY; 
     } 
    } 

    self.toolBar.frame = toolBarRect; 
    [self.toolBar layoutIfNeeded]; 

}; 

Спасибо ша за помощью

Смежные вопросы