sh-khashimov / SwiftFortuneWheel

The ultimate spinning wheel view that supports dynamic content and rich customization.
MIT License
351 stars 82 forks source link

Finish index to be at pin image #9

Closed oenama closed 4 years ago

oenama commented 4 years ago

How can we get the finished index to be at pin image if it was on top?

any idea? @sh-khashimov

oenama commented 4 years ago

like in here I wanna get/print the prize ($200) on startAnimating - > finished IMG_8753

@sh-khashimov

sh-khashimov commented 4 years ago

when you start rotation animation, you specify the finish index. Please, read the API overview.

oenama commented 4 years ago

when you start rotation animation, you specify the finish index. Please, read the API overview.

I did, but how can I add the finished index at pin image position? or like if I wanted it to be random and still need to get the prize title at pin image position

@sh-khashimov from VariousWheelSimpleViewController.swift

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

   wheelControl.startAnimating(indefiniteRotationTimeInSeconds: 1, finishIndex: finishIndex) { (finished) in
            print(finished)
            if finished {
                print(self.finishIndex)
                /// --> here
                print(self.prizes[self.finishIndex]) 
            }
      }
sh-khashimov commented 4 years ago

Regardless of your pin position, if configuration.wheelPreferences.startPosition set to .top, your rotation animation will stop at specified finishIndex. if configuration.wheelPreferences.startPosition set to .top and your pin also on the top position, rotation always stops at the top. (at the pin position)

code from VariousWheelSimpleViewController.swift won't work for you. self.finishIndex is a computed property, when you call print(self.finishIndex), it will return a new random number.

sh-khashimov commented 4 years ago

try this:

let _finishIndex = self.finishIndex
wheelControl.startAnimating(indefiniteRotationTimeInSeconds: 1, finishIndex: _finishIndex) { (finished) in
            print(finished)
            if finished {
                print(_finishIndex)
                /// --> here
                print(self.prizes[_finishIndex]) 
            }
      }
oenama commented 4 years ago

Regardless of your pin position, if configuration.wheelPreferences.startPosition set to .top, your rotation animation will stop at specified finishIndex. if configuration.wheelPreferences.startPosition set to .top and your pin also on the top position, rotation always stops at the top. (at the pin position)

code from VariousWheelSimpleViewController.swift won't work for you. self.finishIndex is a computed property, when you call print(self.finishIndex), it will return a new random number.

I completely missed that, Thank you for your help