簡體   English   中英

在水平滾動UICollectionView內的UICollectionViewCell上垂直滾動

[英]Vertical scrolling on UICollectionViewCell inside the Horizontal Scrolling UICollectionView

我有兩個單元格的collectionview。 一個用於登錄,另一個用於分頁的注冊。 在每個單元格中,我需要垂直滾動。

我試圖在集合視圖單元格中保留垂直scrollview,但它不起作用。

在表視圖中看到了很少的教程和問題放置集合視圖。 但是想知道我們可以在水平滾動集合視圖的單元格內部保持垂直滾動視圖或任何其他選項來實現此目的

您可以將垂直滾動視圖放入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;
}

我遇到了同樣的問題,這里有兩種方法可以嘗試:

  1. 如果要垂直滾動,可以設置視圖框高度> collectionView框高。
  2. 您可以覆蓋hitTest:event方法,添加您想要的下一個響應者的查找視圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM