我有一個小的方法,我打電話來隨着遊戲的進行逐漸繪製恆星。下面是代碼:`UIView alpha值問題
-(void)stars{
for (int i = 0; i < (ScoreNumber * 3); i++){
int starX = ((arc4random() % (320 - 0 + 1)) + 0);
int starY = ((arc4random() % (640 - 0 + 1)) + 0);
int starSize = ((arc4random() % (1 - 0 + 1)) + 1);
UIView *stars = [[UIView alloc] initWithFrame:CGRectMake(starX,starY, starSize, starSize)];
stars.alpha = (i/5);
stars.backgroundColor = [UIColor whiteColor];
[self.view addSubview:stars];
}
}
明星做節目,而是通過循環它蟲子另一個的UIImageView(主角)每次迭代並復位它的位置。此外,阿爾法值似乎根本不起作用,它似乎只使用值1(完整顯示)。任何建議(對於新的程序員)將不勝感激。
一旦'i'大於5,alpha就會是1.即使在前4個循環中alpha也被設置爲1? – trevorj 2014-09-13 11:18:52
是的,這實際上是我的意圖,但是,正如我在下面指出的那樣,我做了一個愚蠢的數學監督。 – Frankeex 2014-09-14 11:35:32