Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone xcode CGPoint arc4random不工作_Iphone_Xcode_Cgpoint_Arc4random_Xvalue - Fatal编程技术网

Iphone xcode CGPoint arc4random不工作

Iphone xcode CGPoint arc4random不工作,iphone,xcode,cgpoint,arc4random,xvalue,Iphone,Xcode,Cgpoint,Arc4random,Xvalue,我有22张照片。。。11个是(右墙1、右墙2、右墙3等)其他11个是(左墙1、左墙2、左墙3等) 我通过将它们的y值设置为前一面墙的y值加上墙的高度(所有墙的高度相同),将它们放置在另一面墙的顶部 这个很好用 现在,我试着用arc4random设置x值,这样他们就可以在一定范围内跳到所有地方 右边的墙工作得很好,但左边的墙,其中一些可以工作,但大部分都不会显示在屏幕上 我手动将x值设置为-15,它显示在屏幕上,低于arc4random允许的值 我能想到的唯一问题是我把左边的墙减去了错误的数 这是

我有22张照片。。。11个是(右墙1、右墙2、右墙3等)其他11个是(左墙1、左墙2、左墙3等)

我通过将它们的y值设置为前一面墙的y值加上墙的高度(所有墙的高度相同),将它们放置在另一面墙的顶部

这个很好用

现在,我试着用arc4random设置x值,这样他们就可以在一定范围内跳到所有地方

右边的墙工作得很好,但左边的墙,其中一些可以工作,但大部分都不会显示在屏幕上

我手动将x值设置为-15,它显示在屏幕上,低于arc4random允许的值

我能想到的唯一问题是我把左边的墙减去了错误的数

这是设置墙位置的代码,我在整个项目中还没有其他代码

-(void)awakeFromNib {

    rightWall1.center = CGPointMake( ((arc4random()%75)+330), (460-((rightWall1.frame.size.height)/2)) );//460 = bottom of screen
    rightWall2.center = CGPointMake( ((arc4random()%75)+330), ((rightWall1.center.y)-(rightWall2.frame.size.height)) );
    rightWall3.center = CGPointMake( ((arc4random()%75)+330), ((rightWall2.center.y)-(rightWall3.frame.size.height)) );
    rightWall4.center = CGPointMake( ((arc4random()%75)+330), ((rightWall3.center.y)-(rightWall4.frame.size.height)) );
    rightWall5.center = CGPointMake( ((arc4random()%75)+330), ((rightWall4.center.y)-(rightWall5.frame.size.height)) );
    rightWall6.center = CGPointMake( ((arc4random()%75)+330), ((rightWall5.center.y)-(rightWall6.frame.size.height)) );
    rightWall7.center = CGPointMake( ((arc4random()%75)+330), ((rightWall6.center.y)-(rightWall7.frame.size.height)) );
    rightWall8.center = CGPointMake( ((arc4random()%75)+330), ((rightWall7.center.y)-(rightWall8.frame.size.height)) );
    rightWall9.center = CGPointMake( ((arc4random()%75)+330), ((rightWall8.center.y)-(rightWall9.frame.size.height)) );
    rightWall10.center = CGPointMake( ((arc4random()%75)+330), ((rightWall9.center.y)-(rightWall10.frame.size.height)) );
    rightWall11.center = CGPointMake( ((arc4random()%75)+330), ((rightWall10.center.y)-(rightWall11.frame.size.height)) );


    leftWall1.center = CGPointMake( ((arc4random()%75)-60), (460-((leftWall1.frame.size.height)/2)) );
    leftWall2.center = CGPointMake( ((arc4random()%75)-60), ((leftWall1.center.y)-(leftWall2.frame.size.height)) );
    leftWall3.center = CGPointMake( ((arc4random()%75)-60), ((leftWall2.center.y)-(leftWall3.frame.size.height)) );
    leftWall4.center = CGPointMake( ((arc4random()%75)-60), ((leftWall3.center.y)-(leftWall4.frame.size.height)) );
    leftWall5.center = CGPointMake( ((arc4random()%75)-60), ((leftWall4.center.y)-(leftWall5.frame.size.height)) );
    leftWall6.center = CGPointMake( ((arc4random()%75)-60), ((leftWall5.center.y)-(leftWall6.frame.size.height)) );
    leftWall7.center = CGPointMake( ((arc4random()%75)-60), ((leftWall6.center.y)-(leftWall7.frame.size.height)) );
    leftWall8.center = CGPointMake( ((arc4random()%75)-60), ((leftWall7.center.y)-(leftWall8.frame.size.height)) );
    leftWall9.center = CGPointMake( ((arc4random()%75)-60), ((leftWall8.center.y)-(leftWall9.frame.size.height)) );
    leftWall10.center = CGPointMake( ((arc4random()%75)-60), ((leftWall9.center.y)-(leftWall10.frame.size.height)) );
    leftWall11.center = CGPointMake( ((arc4random()%75)-60), ((leftWall10.center.y)-(leftWall11.frame.size.height)) );

}
我手动将x值设置为-15,它显示在屏幕上,低于arc4random允许的值


((arc4random()%75)-60)
返回介于-60和14之间的数字,因为
(arc4random()%75)
返回介于0和74之间的数字。

ohhhhhhhhh!哈哈哈哈哈还是不行,问题是当处理负ARC4随机值时,你不能使用整数,你必须使用浮点数。。如果减法不能只是减法,则必须将arc4random乘以负1浮点值。这是因为arc4random使用我假设的模…arc4random返回无符号值。使用%限制范围。您不需要浮点数,只需要%之后的有符号整数。