I have a collection view with a custom flow layout, and many different cells of different height. The width of the collection view changes on device rotation, so the width of cells must change accordingly. For this to work, I implemented “sizeForItemAtIndex” method, and return different sizes depending on current interface orientation.
Most of the cells do not change their height, however, there is one cell that I want to expand and collapse whenever the user taps on it. You can assume that the cell only has one UILabel with one or more lines of text. When the cell appear for the first time the number of lines is set to 1, and when user taps on the cell the number of lines is set to 0, and here the cell should use the intrinsic size of the label to change it’s height automatically. How can I achieve this effect?
Here is an example of what it should look like:
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Follow these steps:
1). Create a boolean variable named
isExpanded
to manage expand / collapse2.) Add a target and action to the show more button
3.) In sizeForItemAtIndexPath for managing height, add:
4.) Then in the ShowMoreButtonClicked method
5.) Add this line in your cellForItemAtIndexPath
6.) Build & run
The previous response is good but if you want some animation you need to do this three steps:
1.Invalidate your collectionViewLayout
2.Reload desired indexPath or all the data inside a performBatchUpdates block
3.Return the new height calculated in
sizeForItemAtIndexpath
delegate method