Maison > Questions et réponses > le corps du texte
我想实现的效果是这样的:
首页上显示一个轮播器,轮播器用Masonry
实现,轮播器下面是一个tableview,并且用Masonry
进行自动布局。
UI用代码实现。
NSArray* imageNames = @[@"checked", @"test1"];
_vCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 180) imageNamesGroup:imageNames];
[self.view addSubview:_vCycleScrollView];
[_vCycleScrollView mas_makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.view);
make.left.equalTo(self.view);
make.right.equalTo(self.view);
make.width.equalTo(self.view.mas_width);
}];
_vCategoryTableView = [[UITableView alloc] init];
_vCategoryTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_vCategoryTableView.delegate = self;
_vCategoryTableView.dataSource = self;
[self.view addSubview:_vCategoryTableView];
[_vCategoryTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view);
make.top.equalTo(_vCycleScrollView).with.offset(10);
make.width.mas_equalTo(self.view.mas_width);
make.height.equalTo(self.view);
}];
轮播器完全显示不出来。
如果单把scrollview的constraint注释掉,可以显示出图片的底边
如何解决?
PHP中文网2017-04-17 18:03:34
[_vCycleScrollView mas_makeConstraints:^(MASConstraintMaker* make){
make.top.equalTo(self.view.mas_top);
make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right);
make.height.equalTo(@168);
}];
[_vCategoryTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right);
make.top.equalTo(_vCycleScrollView.mas_bottom).with.offset(10);
make.bottom.equalTo(self.view.mas_bottom);
}];
Une telle image de carrousel est fixée en haut. Si vous souhaitez que l'image du carrousel glisse avec la tableview, vous pouvez alors utiliser l'image du carrousel comme en-tête de la tableview et définir le cadre de l'image du carrousel.
Lorsque j'utilise la maçonnerie, make.right.equalTo(self.view) contraindra la droite à gauche de la vue.
Si c'est make.top.left.bottom.right.equalTo(self.view), c'est la bonne position, je suppose que cela correspond à UIEdgeinsets