iOS:键盘出现时触发了什么事件

时间:2015-02-06 13:12:12

标签: ios objective-c swift uicollectionview

我正在使用JSQMessagesController处理我正在处理的项目并在Github页面上打开了一个问题,但是在与作者协商后我们无法解决问题。

我有一个由一个消息列表填充的collectionView,但是当首次加载视图时,顶部消息从屏幕顶部被切断,当键盘显示并被解除时,视图按预期显示下面:

demonstrates broken message controller

当显示键盘时,显然会触发一个事件,重新验证布局,但它是什么?我尝试了以下步骤:

self.collectionView.collectionViewLayout.invalidateLayout()
self.collectionView.reloadData()

但这并没有解决问题 - 任何见解都会受到赞赏。

编辑:测试后,当我为视图设置背景图像时,视图层次结构似乎无效:

backgroundView = UIImageView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
backgroundView.image = UIImage(named: "background")
self.view.insertSubview(backgroundView, atIndex: 0)

删除这些行会消除不受欢迎的上边距,但是调出键盘仍会解决损坏的约束。

4 个答案:

答案 0 :(得分:1)

你有没有试过下面的解决方案...

- (void)viewWillLayoutSubviews //(要么) - (void)viewDidLoad方法

self.navigationController.navigationBar.translucent = NO;

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

希望它可以帮助你......!

答案 1 :(得分:1)

您是否尝试更改集合视图的插图?类似的东西:

[self.collectionView setContentInset:UIEdgeInsetsMake(64.0, 0.0, 0.0, 0.0)];

答案 2 :(得分:1)

好吧,要更新代码中的约束,您必须执行以下操作:

[self.collectionView removeConstraints:self.collectionView.constraints];
NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.collectionView
                             attribute:NSLayoutAttributeTop
                             relatedBy:NSLayoutRelationEqual
                                toItem:self.topLayoutGuide
                             attribute:NSLayoutAttributeBottom
                            multiplier:1.0
                              constant:0.0];
NSLayoutConstraint *leading = [NSLayoutConstraint
                               constraintWithItem:self.collectionView
                               attribute:NSLayoutAttributeLeading
                               relatedBy:NSLayoutRelationEqual
                               toItem:self
                               attribute:NSLayoutAttributeLeading
                               multiplier:1.0f
                               constant:0.f];
NSLayoutConstraint *trailing = [NSLayoutConstraint
                               constraintWithItem:self.collectionView
                               attribute:NSLayoutAttributeTrailing
                               relatedBy:NSLayoutRelationEqual
                               toItem:self
                               attribute:NSLayoutAttributeTrailing
                               multiplier:1.0f
                                constant:0.f];
NSLayoutConstraint *bottom = [NSLayoutConstraint
                                constraintWithItem:self.collectionView
                                attribute:NSLayoutAttributeBottom
                                relatedBy:NSLayoutRelationEqual
                                toItem:self.bottomLayoutGuide
                                attribute:NSLayoutAttributeTop
                                multiplier:1.0f
                                constant:0.f];

[self.collectionView addConstraints:@[top,leading,trailing,bottom]];

答案 3 :(得分:0)

您可以使用您使用的delegate的{​​{1}}方法:

UITextField

相关问题