iCarousel - how do I turn off infinite scroll?

253 views Asked by At

I simply use iCarousel library for displaying items in carousel.

But when I swipe left and have for example 5 items it is rotated a few times around. How can I prevent from rotating left when currentIndex is 0 and prevent from rotating right when currentIndex is set to maximum.

This is how I define my carousel as well as its data source:

let carousel: iCarousel = {
    let view = iCarousel()
    view.type = .invertedCylinder
    view.perspective = -0.0025
    view.clipsToBounds = true
    return view
}()

// MARK: - iCarouselDataSource

func numberOfItems(in _: iCarousel) -> Int {
    viewModel.cards.count
}

func carousel(_: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
    let view = view as? UIImageView ?? mainView.cardImageViewForCarousel
    view.image = nil
    if let url = viewModel.backImageUrl(atIndex: index) {
        view.setImage(with: url)
    }
    return view
}

func carousel(_: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    if option == .visibleItems {
        return 3
    } else if option == .spacing {
        return value * 1.1
    } else if option == .count {
        return 7
    }
    return value
}
1

There are 1 answers

1
EmilioPelaez On

Setting the wrapEnabled property to false should disable that functionality.