TTFortuneWheel-iOS icon indicating copy to clipboard operation
TTFortuneWheel-iOS copied to clipboard

How to get the slice value at Finish State

Open abdurrazax opened this issue 4 years ago • 1 comments
trafficstars

Is there any option to get the top value or any pointing value after the spinner will stop ? I'm need the index of slice at the top.

abdurrazax avatar Jun 21 '21 12:06 abdurrazax

@IBOutlet weak var spinningWheel: TTFortuneWheel!{
    didSet {
        
        spinningWheel.slices = slices
        spinningWheel.equalSlices = true
        spinningWheel.frameStroke.width = 0
        spinningWheel.titleRotation = CGFloat.pi
        spinningWheel.slices.enumerated().forEach { (pair) in
            let slice = pair.element as! CarnivalWheelSlice
            let offset = pair.offset
            switch offset % 4 {
            case 0: slice.style = .brickRed
            case 1: slice.style = .sandYellow
            case 2: slice.style = .babyBlue
            case 3: slice.style = .deepBlue
            default: slice.style = .brickRed
            }
        }
    }
}

var prizes = ["0", "5", "15", "18", "10", "20", "3", "9"]

lazy var slices: [CarnivalWheelSlice] = {
    let slices = prizes.map({CarnivalWheelSlice.init(title: $0) })
    return slices
}()

var finishIndex: Int {
    return Int.random(in: 0..<spinningWheel.slices.count)
}

//// Usage let _finishIndex = self.finishIndex spinningWheel.startAnimating() self.spinningWheel.startAnimating(fininshIndex: _finishIndex) { (finished) in print(self.prizes[_finishIndex]) }

IshuRocks avatar Oct 28 '21 08:10 IshuRocks

The finish state is predefinied and sent asa a parameter to startAnimating.

EfraimB avatar Nov 11 '22 10:11 EfraimB