0

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.

user1625435
  • 153
  • 8

1 Answers1

3

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];
Alex Salom
  • 3,074
  • 4
  • 22
  • 33
  • Technically speaking that is not a function it is a method. It would probably make more sense as a function as I am sure it does not need to belong to a particular class. – Paul.s Nov 03 '12 at 09:03