【问题标题】:Vertical scrolling on UICollectionViewCell inside the Horizontal Scrolling UICollectionView水平滚动 UICollectionView 内的 UICollectionViewCell 上的垂直滚动
【发布时间】:2017-06-17 04:04:15
【问题描述】:
我有两个单元格的collectionview。一个用于登录,另一个注册类似于分页。
在每个单元格中,我需要垂直滚动。
我试图在集合视图单元格中保留一个垂直滚动视图,但它不起作用。
见过很少的教程和问题将集合视图放在表格视图中。但是想知道我们是否可以在水平滚动collectionview的单元格内保留垂直滚动视图或任何其他选项来实现这一点
【问题讨论】:
标签:
ios
objective-c
uiscrollview
uicollectionviewcell
【解决方案1】:
你可以把垂直滚动视图放到一个tableView中。
直接放到tableViewCell的contentView中即可,示例代码:
- (void)viewDidLoad {
[super viewDidLoad];
UITableView* tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[self.view addSubview:tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
UIScrollView* sv = [[UIScrollView alloc] init];
CGRect rect = CGRectZero;
rect.size.width = self.view.bounds.size.width;
rect.size.height = 60;
sv.frame = rect;
sv.contentSize = CGSizeMake(1000, 60);
UILabel* label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 0, 900, 30);
label.text = @"hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello ";
label.adjustsFontSizeToFitWidth = true;
[sv addSubview:label];
[cell.contentView addSubview:sv];
return cell;
}
【解决方案2】:
我遇到了同样的问题,你可以尝试以下两种方法:
- 如果你想垂直滚动,你可以设置你的视图框架高度>collectionView框架高度。
- 您可以覆盖
hitTest:event 方法,添加您想要下一个响应者的查找视图