2015-02-06 88 views
0

我正在使用JSQMessagesController來處理我正在處理的項目,並在Github頁面上打開了一個問題,但是在與作者進行一些諮詢之後,我們無法解決問題。iOS:當鍵盤出現時觸發什麼事件

我有一個由消息列表填充的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) 

刪除這些線擺脫不需要的頂緣,但是帶來了將鍵盤仍然解決破壞的約束。

+0

您需要的UICollectionView頂部約束設爲首頁佈局指南,以便視圖正確放置在UINavigationBar下面 – Lefteris 2015-02-06 13:14:26

+0

您能否提供一個關於如何做到這一點的答案,以便我可以接受它? :) – Alex 2015-02-06 13:15:41

+0

你在使用故事板嗎? – Lefteris 2015-02-06 13:32:55

回答

1

您是否嘗試更改集合視圖的插圖?喜歡的東西:

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

+0

謝謝Validimir - 這對我有效:) – Alex 2015-02-06 14:03:21

+0

你很好:) – 2015-02-06 14:05:07

0

您可以使用UITextFielddelegate方法,您使用:

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

+0

中手動設置它。但是,我會使用它似乎JSQMessageController的UITextView是一個私人成員,因此我不能調用它的手動委託方法 – Alex 2015-02-06 13:26:06

+0

啊我看到了,那麼沒關係我的回答:) – nburk 2015-02-06 13:26:44

+0

沒問題 - 謝謝:) – Alex 2015-02-06 13:27:04

1

具有u嘗試以下solution..at

- (無效)viewWillLayoutSubviews //(OR) - (void)viewDidLoad方法

self.navigationController.navigationBar.translucent = NO; 

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

Hope它可以幫助你...!

+0

嘿,這個工程很好 - 但它移動我的標籤欄到屏幕的頂部 – Alex 2015-02-06 13:52:42

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]]; 
相關問題