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

Cycling custom type animation #905

Open maukur opened 2 years ago

maukur commented 2 years ago

Does anyone know how I can cycle custom type?

Layout my view looks like this:

image

I use a custom type from here: Link


func carousel(_ carousel: iCarousel, itemTransformForOffset offset: CGFloat, baseTransform transform: CATransform3D) -> CATransform3D {
            let centerItemZoom: CGFloat = 1.329
            let centerItemSpacing: CGFloat = 1.41

            let spacing: CGFloat = 0.87
            let absClampedOffset = min(1.0, abs(offset))
            let clampedOffset = min(1.0, max(-1.0, offset))
            let scaleFactor = 1.0 + absClampedOffset * (1.0/centerItemZoom - 1.0)
            let offset = (scaleFactor * offset + scaleFactor * (centerItemSpacing - 1.0) * clampedOffset) * carousel.itemWidth * spacing
            var transform = CATransform3DTranslate(transform, offset, 0.0, -absClampedOffset)
            transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 1.0)
            transform = CATransform3DTranslate(transform, 0, 11, 0)
            return transform
        }