ios - Repeat a function in set time Intervals -
i'v been using xcode/swift couple weeks , i'm working on first little ios game. nothing tricky trying learn program , having fun. leads me problem...
...i want background image have in app change randomly (from set of values in array) timed. example "every 2 seconds background image changes."
this have far, i've seen stuff nstimer i'm not sure how implement have.
@iboutlet weak var backview: uiimageview! let backnames = ["back 1", "back 2", "back 3", "back 4", "back 5", "back 6", "back 7"] let backvalue = int(arc4random_uniform(7)) backview.image = uiimage (named: backnames [backvalue])
so yeah said, know how make select random value background, happens when tap button. wondering how incorporate time feature arc4random.
thanks!
try animation of image :
var imglistarray :nsmutablearray = ["back 1", "back 2", "back 3", "back 4", "back 5", "back 6", "back 7"] countvalue in 1...7 { var strimagename : string = "back \(countvalue).png" var image = uiimage(named:strimagename) imglistarray .addobject(image) } self.imageview.animationimages = imglistarray; self.imageview.animationduration = 1.0 // change per requirement self.imageview.startanimating()
Comments
Post a Comment