简体   繁体   中英

Scroll horizontally in UITableView - Swift 3, iOS

I need to horizontally scroll through a list of thumbnails at the bottom of the screen that shows all the user's recently taken photos / videos.

I created a UIScrollView with a UITableview inside of it.

Is this the correct approach because I can't seem to find an override method in its superclass for scrolling direction? Most of the topics I can find online deals with putting a UIscrollview inside a TableCell, which will not work for my specific application?

The hierarchy is:

View > Scroll View > Table View > Table Cel > Content > PhotoThumbnail

Below is a screenshot of what I'm trying to do: 在此处输入图片说明

I am not really sure why do you want to use UITableView for horizontal scrolling which lay out there cells in vertical manner. If you want horizontal scrolling I would recommend using UICollectionView where cells can be added horizontally or vertically or both. Still if you want tableview to be scrollable in horizontal direction I would suggest you to check this project to get inspiration or using it.

https://github.com/alekseyn/EasyTableView

可以使用UICollectionView来获得所需的结果,而不是使用UITableView,即使用imageView和所需的其他元素来水平滚动单元格。

For swift 5.1

  1. firstly put scrollView give constraint to superView. Make them all what you desire.

  2. Then put view on scroll view like I showed in pic. Give constraint shown below then to avoid error follow 3. step.

  1. Push control button and drag to the view then select Equal Height.
  1. I give name to view over scrollview which name is ContentView . Be sure view size form is freeform and make width 1200 same as ContentView.

5)Then put TableView over the ContentView and give all the constraint zero.

  1. This is my TableviewCell
  1. And this one is the result.

https://i.stack.imgur.com/zxBAT.gif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM