如何在我的代码中更改此号码“63”?
-(void)up
{
[UIView animateWithDuration:[self randomFloatBetween:1.0 and:0.3] animations:^{
m1.center = CGPointMake(63, 210);
}];
[self performSelector:@selector(down) withObject:nil afterDelay:[self randomFloatBetween:1.0 and:0.5]];
}
我的CGPointMake中的63号应该是随机的。所以对于数字63,我需要随机这些数字:160& 257.
我的“m1”图像出现在CGPointMake(63,210),但我想让Point 63随机,从63变为160或257. RANDOM。深受欢迎。
答案 0 :(得分:1)
将所需的数字添加到NSArray,然后使用[yourArray objectAtIndex:(arc4random()%yourArray.count)];
答案 1 :(得分:1)
-(void)up
{
NSArray *myArray = [NSArray arrayWithObjects:[NSNumber numberWithFloat:63],[NSNumber numberWithFloat:160],[NSNumber numberWithFloat:257], nil];
[UIView animateWithDuration:[self randomFloatBetween:1.0 and:0.3] animations:^{
m1.center = CGPointMake([[myArray objectAtIndex:arc4random() % [myArray count]] floatValue], 210);
}];
[self performSelector:@selector(down) withObject:nil afterDelay:[self randomFloatBetween:1.0 and:0.5]];
}
也许这会有所帮助。