0

I'm working in a collection view where one of our cells is able to be collapsed or expanded with a button press. The original developer of this feature is gone, so I'm trying to understand what all is going on. From what I can tell, when the user presses the button, the following code gets called:

- (void)expandCell{
    [expandCollapseButton setTitle:@"-" forState:UIControlStateNormal];
    [textView setHidden:NO];
    isExpanded = YES;

    [self.delegate cellDidExpandCollapse];
}

Our collapse cell is virtually identical except we don't hide it, set the isExpanded variable to NO and set the title to be "+" instead of "-". The cellDidExpandCollapse delegate method simply calls an updateCollection method, which I've copied below.

- (void)updateCollection {
    [self.collection performBatchUpdates:nil completion:nil];
    [self.amountCell updateTable];
    [self.collection setNeedsLayout];
    [self.collection layoutIfNeeded];
}

And that's it. Yet, when layoutIfNeeded is called, the system sets the frame of the textView to have a different origin and a height of 0. I'm not sure why, from my understanding, a hidden view is still "present", it just has an alpha of 0. Since I'm not calling any frame updating logic on the textView when I hit the button, I'm not sure how the frame is actually being set.

Are there any properties of a collectionView or a view in general that you can set to have the frame collapse its height when its hidden? Or is there any other magic properties I should be looking into?

Edit: The views are not setup in a stack view, so it shouldn't be resizing, at least as far as I understand.

Bill L
  • 2,576
  • 4
  • 28
  • 55

1 Answers1

0

Did you use Auto Layout on the cell? If so, the hidden view still participates in the layout. Please refer to this How to use auto-layout to move other views when a view is hidden?

Community
  • 1
  • 1
Evan
  • 430
  • 6
  • 16