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
}
Setting the wrapEnabled
property to false
should disable that functionality.
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.