IOS - How to create TabelView with horizontal scro

2019-01-31 11:44发布

I'm trying to implement a table view with scrollable horizontal items (with unknown number of items) like the illustration below:

enter image description here

The UI should behave like so:

  1. At the init state the table cell shows a label and some text and the circle item pops out of the right side
  2. If the users swipes from right to left, the label and text fades out and the horizontal list (inside the cell) takes it's place

I thought about using TableView and dequeueReusableCellWithIdentifier and creating a prototype cell, but then I need to remember the list horizontal position and init the cell properly on cellForRowAtIndexPath and that will probably affect performance.

Q: What layout would you use in order to achieve this goal, any input / tutorial would be appreciated

3条回答
对你真心纯属浪费
2楼-- · 2019-01-31 11:54

Use a UITableView and add a UICollectionView to your reusable tableView cell. UICollectionView works similar to UITableView in that the "items" (like cells) are reusable and instantiated only when they will appear on screen. I did a quick google search for tutorials and found UICollectionView in UITableViewCell. Check that out and a few other StackOverflow questions regarding design and you should be golden.

查看更多
迷人小祖宗
3楼-- · 2019-01-31 12:07

Using UIScrollView may require heavy effort if there are large amount of UI elements inside each scrollview because you have to instantiate all those upfront. A better solution is to define your custom UITableViewCell which has its own UITableView but rotated in 90 degree for horizontal scrolling. UI elements inside will be created only when they need to be shown by using dequeueReusableCellWithIdentifier:forIndexPath:. Please see some sample code on how to create a 90 degree rotated table view:

iPhone Tableview Use Cells in Horizontal Scrolling not Vertical

查看更多
叛逆
4楼-- · 2019-01-31 12:09

You can use a ScrollView to put inside your tableview and set the values "Direction lock enabled" and "Paging Enabled" to true for the scrollview.

查看更多
登录 后发表回答