Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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 使用随机方法随机创建图像视图,其中一幅图像的概率更大_Iphone_Xcode_Random_Timer_Uiimageview - Fatal编程技术网

Iphone 使用随机方法随机创建图像视图,其中一幅图像的概率更大

Iphone 使用随机方法随机创建图像视图,其中一幅图像的概率更大,iphone,xcode,random,timer,uiimageview,Iphone,Xcode,Random,Timer,Uiimageview,我有一个uIImageView“image1”,它是用计时器每秒钟创建一次的。我还有另一个uIImageView“image2”。我想要的是,每秒钟随机出现在屏幕上的是“image1”或“image2”,而不是仅仅出现“image1”,而且“image1”出现在屏幕上的几率更大,如(80%以上)。我该怎么做呢?只需在5个值之间随机选择,而不是2个值。对于这5个值中的1个,您将选择image2,对于所有其他4个值,您将选择image1是否不可能以其他方式执行?因为我害怕有人会给出这样的回答:)。这

我有一个uIImageView“image1”,它是用计时器每秒钟创建一次的。我还有另一个uIImageView“image2”。我想要的是,每秒钟随机出现在屏幕上的是“image1”或“image2”,而不是仅仅出现“image1”,而且“image1”出现在屏幕上的几率更大,如(80%以上)。我该怎么做呢?

只需在5个值之间随机选择,而不是2个值。对于这5个值中的1个,您将选择image2,对于所有其他4个值,您将选择image1

是否不可能以其他方式执行?因为我害怕有人会给出这样的回答:)。这种方法很容易做到,但需要更多的内存,我想在应用程序中使用“值”来更改80%到50%,然后更改到90%,例如,按照您的方式,很难更改然后执行
r=arc4random()%100
来选择范围
[0-100]内的随机数[
,并将其与所需的百分比值进行比较。如果在某一点上需要image1比image2的频率高80%,则选择image1 If
r