iCarousel没有在Swift中滚动SpriteKit

时间:2016-12-20 13:59:02

标签: ios swift xcode sprite-kit icarousel

我正在尝试在SKScene中使用iCarousel。问题是,当我拖动旋转木马时,它不会改变图像。我还没有在SpriteKit中找到iCarousel的教程,所以很多都是猜测。

这是我的代码:

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
    }

}

屏幕截图:simulator

iCarousel正在出现,但不会滚动。

我错过了什么?

使用自动滚动但不能正常滚动时,滚动会起作用。

0 个答案:

没有答案