nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12k stars 2.58k forks source link

How to scroll horizontally when a user scrolls the a tableview #852

Open EddieMa opened 6 years ago

EddieMa commented 6 years ago

Hi everyone,

I am using this amazing class to build a card view. But I have one issue which is how to achieve vertical scroll when it is a horizontal model when it is in a tableview cell and the user scrolls down/up the tableview. In other word, I want to implement users scroll down/up the tableview, the iCarousel also be scrolled horizontally.

Thanks in advance Eddie

nicklockwood commented 6 years ago

The best bet is probably to set the carousel.scrollOffset property programmatically from inside your UITableViewDelegate’s scrollViewDidScroll method.

EddieMa commented 6 years ago

@nicklockwood , thank you for your reply, could you please give me more hints about how to set customized scrollOffset?

nicklockwood commented 6 years ago

(In swift)

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    carousel.scrollOffset.x = scrollView.contentOffset.y / carousel.itemWidth
}

You may need to multiply the scrollView offset by some constant to get the exact effect you want.