Reputation: 153
i want to animate my image with random duration, and random delay. help me please. I'm beginner. here is the code:
-(void)up
{
[UIView animateWithDuration:0.3 animations:^{
mole.center = CGPointMake(63, 210);
}];
[self performSelector:@selector(down) withObject:nil afterDelay:1.0];
}
So, i need "0.3" from duration and 1.0 from delay to be random. like, between 0.0 and 1.0. Thanks.
Upvotes: 0
Views: 333
Reputation: 3094
Here is a function:
- (float)randomFloatBetween:(float)smallNumber and:(float)bigNumber {
float diff = bigNumber - smallNumber;
return (((float) (arc4random() % ((unsigned)RAND_MAX + 1)) / RAND_MAX) * diff) + smallNumber;
}
I found it here.
You would call it like this:
[self randomFloatBetween:0.0 and:1.0];
Upvotes: 3