TTFortuneWheel-iOS
TTFortuneWheel-iOS copied to clipboard
How to get the slice value at Finish State
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.
@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]) }
The finish state is predefinied and sent asa a parameter to startAnimating.