@objc func updateRandom(){
if(counter >= 1 && counter <= 200){
self.shakeAction()
}
if(counter > 200){
self.ReTime()
}
counter += 1
}
public func shakeAction(){
let datepickerViewMiddle = dateStrings.count
let payerpickerViewMiddle = payerStrings.count
print ("Shake")
print (datepickerViewMiddle)
print (payerpickerViewMiddle)
random1=Int(arc4random_uniform(UInt32(datepickerViewMiddle)+1))
random2=Int(arc4random_uniform(UInt32(payerpickerViewMiddle)+1))
//random1=Int(arc4random_uniform(UInt32(4)+1))
dateOptions.selectRow(random1-1, inComponent: 0, animated: true)
let when = DispatchTime.now() + 0.5 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
// Your code with delay
self.payerOptions.selectRow(self.random2-1, inComponent: 0, animated: true)
}
print(random1)
print(random2)
if (UserDefaults.standard.object(forKey: "ShakeCount") as? Int) != nil
{
var x = UserDefaults.standard.object(forKey: "ShakeCount") as? Int
x = x!+10;
UserDefaults.standard.set(x, forKey: "ShakeCount")
}
else{
UserDefaults.standard.set(5, forKey: "ShakeCount")
}
}
func ReTime(){
if(rolling == false){
counter=0
rolling = true
self.updateRandom()
}
else{
rolling = false
timer.invalidate()
counter=0
}
}
I am building a slot machine in IOS Swift, and I am having trouble getting to look like more of a slot machine. I can get the picker view to spin but only a little, it only seems to move a few rows and sometimes doesn't move at all. Therefore, I would like to know how to get a consistent spin out of the pickerview to make it look. What I have it doing right now is basically just taking the pickerview and randomly selecting a row 200 times in order to make it look like it's kind of spinning, but not for as long as I would like. I have been trying to research this and haven't really found anything that could help me in this specific situation. The things I have found are either outdated or are just doing the same thing I am already doing, Therefore I would appreciate the help on fixing this issue.
Comments
Post a Comment