iCarousel not scrolling SpriteKit in Swift

235 views Asked by At

I'm trying to use an iCarousel in an SKScene. The problem is that when I drag on the carousel it doesn't change the images. I haven't found a tutorial for iCarousel in SpriteKit so a lot of this was guesswork.

This is my code:

import UIKit
import SpriteKit

class Hobbies: SKScene, iCarouselDelegate, iCarouselDataSource {

    var carousel : iCarousel = iCarousel()

    var imageArray : NSMutableArray = NSMutableArray()

    override func didMove(to view: SKView) {

        carousel.delegate = self
        carousel.dataSource = self

        carousel.type = .cylinder
        carousel.center = CGPoint(x: self.size.width / 2, y: self.size.height / 2)

       carousel.isUserInteractionEnabled = true
       carousel.reloadData()

       self.view?.addSubview(carousel)
    }


    func numberOfItems(in carousel: iCarousel) -> Int {
        imageArray = ["Hobbies1.png", "Hobbies2.png", "Hobbies3.png"]
        return imageArray.count
    }

    func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {

        var imageview : UIImageView!

        if view == nil {
            imageview = UIImageView(frame: CGRect(x: 0, y: 0, width: 250, height: 250))
            imageview.contentMode = .scaleAspectFit
        } else {
            imageview = view as! UIImageView
        }

        imageview.image = UIImage(named: "\(imageArray.object(at: index))")

        return imageview  
    }

    func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {

        if option == iCarouselOption.spacing {
            return value * 1.2
        }

        return value
    }

}

Screenshot: simulator

The iCarousel is appearing but won't scroll.

What am I missing?

The scrolling works when using autoscroll but not with normal scroll.

0

There are 0 answers