iOS:当键盘出现时触发什么事件
我正在使用JSQMessagesController来处理我正在处理的项目,并在Github页面上打开了一个问题,但是在与作者进行一些咨询之后,我们无法解决问题。iOS:当键盘出现时触发什么事件
我有一个由消息列表填充的collectionView,但是当第一次加载视图时,顶部消息从屏幕的顶部切断,当键盘显示并解除视图显示时,以下证明:
当显示键盘,事件显然是烧制时重新验证的布局,但它是什么?我曾尝试以下步骤:
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)
删除这些线摆脱不需要的顶缘,但是带来了将键盘仍然解决破坏的约束。
您是否尝试更改集合视图的插图?喜欢的东西:
[self.collectionView setContentInset:UIEdgeInsetsMake(64.0, 0.0, 0.0, 0.0)];
谢谢Validimir - 这对我有效:) – Alex 2015-02-06 14:03:21
你很好:) – 2015-02-06 14:05:07
具有u尝试以下solution..at
- (无效)viewWillLayoutSubviews //(OR) - (void)viewDidLoad方法
self.navigationController.navigationBar.translucent = NO;
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
Hope它可以帮助你...!
嘿,这个工程很好 - 但它移动我的标签栏到屏幕的顶部 – Alex 2015-02-06 13:52:42
好,更新代码的约束,你会做这样的事情:
[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]];
您需要的UICollectionView顶部约束设为首页布局指南,以便视图正确放置在UINavigationBar下面 – Lefteris 2015-02-06 13:14:26
您能否提供一个关于如何做到这一点的答案,以便我可以接受它? :) – Alex 2015-02-06 13:15:41
你在使用故事板吗? – Lefteris 2015-02-06 13:32:55