pradeep
pradeep

Reputation: 441

Vertical scrolling on UICollectionViewCell inside the Horizontal Scrolling UICollectionView

I have collectionview with two cell. One for login, another signup which works like pagination. In each cell I need to scroll vertically.

I tried to keep a vertical scrollview inside the collection view cell but its not working.

Have seen few tutorial & question putting collection view inside table view. But want to know can we keep vertical scroll view inside cell of horizontal scrolling collectionview or any other option to achieve this

Upvotes: 1

Views: 947

Answers (2)

user8006205
user8006205

Reputation: 1

I encountered the same problem, here are two methods you could try:

  1. If you want vertical scrolling, you can set your view frame height > collectionView frame height.
  2. You can overwrite hitTest:event method, add find view that you want next responder

Upvotes: 0

jokeman
jokeman

Reputation: 1297

You can put the vertical scroll view into a tableView. Just put it into the contentView of the tableViewCell, sample code:

- (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;
}

Upvotes: 0

Related Questions