Ios 如何向JSQMessagesViewController添加自定义视图
如何在“集合”视图的顶部添加自定义视图? 我想使用Xcode用户界面设计一个自定义视图 我在storyBoard view controller中添加了我的视图,但集合视图覆盖了它 因此,我在viewDidLoad中添加了一个自定义视图Ios 如何向JSQMessagesViewController添加自定义视图,ios,objective-c,xcode,jsqmessagesviewcontroller,Ios,Objective C,Xcode,Jsqmessagesviewcontroller,如何在“集合”视图的顶部添加自定义视图? 我想使用Xcode用户界面设计一个自定义视图 我在storyBoard view controller中添加了我的视图,但集合视图覆盖了它 因此,我在viewDidLoad中添加了一个自定义视图 - (void)viewDidLoad { [super viewDidLoad]; [self addViewOnTop]; } } -(void)addViewOnTop { UIView *selectableView =
- (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];
}
self.collectionView?.collectionViewLayout.sectionInset = UIEdgeInsets(top: 40, left: 0, bottom: 0, right: 0)
self.edgesForExtendedLayout = UIRectEdgeNone;
此代码成功运行,但如何使用Xcode interface builder加载视图或加载.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];
}
但是,如果我理解您遇到的真正问题是您的
customView
正在覆盖collectionView
而不是修改故事板,那么它没有任何帮助
添加UIEdgeInset以允许您在新视图下查看消息在viewDidLoad()中调用它
您应该尝试使用
currentView.bringSubview(toFront:)
问题是导航栏隐藏了视图。
但把它带到前线并不能解决问题
但这样做可以解决问题:
在viewDidLoad中
- (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];
}
self.collectionView?.collectionViewLayout.sectionInset = UIEdgeInsets(top: 40, left: 0, bottom: 0, right: 0)
self.edgesForExtendedLayout = UIRectEdgeNone;
好的,开始不是我的问题,但现在是我的问题,但不管我是否编辑了问题@daniel Leonardon你现在的问题是什么?