拥有:
@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];
}但在我看来没有动画:
一些故事:-在故事情节提要1工具栏与约束空间(左,右,按钮)
发布于 2014-11-30 16:52:46
如果使用自动布局配置此视图,则无法对视图的框架进行动画化。相反,您需要公开您需要更改的约束(在您的例子中,我猜是bottom ),并更改此约束的值。
发布于 2014-12-01 09:20:49
我的解决方案:
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];
};谢谢你的帮助
https://stackoverflow.com/questions/27214987
复制相似问题