首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIToolBar + UITextField = Chat

UIToolBar + UITextField = Chat
EN

Stack Overflow用户
提问于 2014-11-30 15:44:10
回答 2查看 176关注 0票数 0

拥有:

代码语言:javascript
复制
@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];

试试这个:

代码语言:javascript
复制
- (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工具栏与约束空间(左,右,按钮)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-30 16:52:46

如果使用自动布局配置此视图,则无法对视图的框架进行动画化。相反,您需要公开您需要更改的约束(在您的例子中,我猜是bottom ),并更改此约束的值。

票数 1
EN

Stack Overflow用户

发布于 2014-12-01 09:20:49

我的解决方案:

代码语言:javascript
复制
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];

};

谢谢你的帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27214987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档