2017-02-14 60 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; 
相关问题