2017-02-14 85 views
0

如何在集合視圖頂部添加自定義視圖? 我想用Xcode的用戶界面 我已經加入我的觀點在故事板視圖控制器,但集合視圖覆蓋它 所以我在viewDidLoad中如何將自定義視圖添加到JSQMessagesViewController中

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self addViewOnTop]; 
    } 
} 
-(void)addViewOnTop { 

    UIView *selectableView = [[UIView alloc]initWithFrame:CGRectMake(0, 60, self.view.bounds.size.width, 40)]; 
    selectableView.backgroundColor = [UIColor redColor]; 
    UILabel *randomViewLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 10, 100, 16)]; 
    randomViewLabel.text = @"RandomView"; 
    [selectableView addSubview:randomViewLabel]; 
    [self.view addSubview:selectableView]; 
} 

此代碼成功,但如何運行添加自定義視圖設計自定義視圖使用Xcode的界面生成器可以裝入一個視圖或加載的.xib文件

現在我做這個

@implementation chatViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [SVProgressHUD dismiss]; 
    self.collectionView.collectionViewLayout.sectionInset = UIEdgeInsetsMake(70, 0, 0, 0); 
    self.collectionView.dataSource = self; 
    self.collectionView.delegate= self; 
    messages = [NSMutableArray array]; 
    [self addMessages]; 
    self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeZero; 
    self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero; 
    self.topContentAdditionalInset = 70.0f; 
    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCollectionTapRecognizer:)]; 
    [self.collectionView addGestureRecognizer:tapRecognizer]; 
    self.collectionView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; 
    [self addViewOnTop]; 
} 
-(void)addViewOnTop { 
    commentsheader *test = [[commentsheader alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 70)]; 
    [self.view addSubview:test]; 

} 

,但它並沒有幫助

回答

0

如果我瞭解您遇到的實際問題是您的customView覆蓋了collectionView而不是修改故事板,只需調整集合視圖的插圖即可。

添加UIEdgeInset,讓您查看郵件的新視圖號召下這個在viewDidLoad中()

self.collectionView?.collectionViewLayout.sectionInset = UIEdgeInsets(top: 40, left: 0, bottom: 0, right: 0) 
+0

確定在第一它不是我的問題,但現在這是我的問題,但無論 我有編輯問題@丹尼爾·萊納德 –

+0

你現在的問題是什麼? –

0

你應該嘗試currentView.bringSubview(toFront: <UIView instance>)

0

的問題是,在導航欄隱藏視圖。 但把它前面沒​​有解決問題 但是這樣做固定它: 在viewDidLoad中

self.edgesForExtendedLayout = UIRectEdgeNone; 
相關問題