那麼這裏是我的問題: 我有兩個圖像:flakeImage和ViewToRotate。我想要的是,如果flakeImage觸及ViewToRotate,ViewToRotate.alpha = 0.5;但是當FlakeImage出現在屏幕上時ViewToRotate.alpha = 0.5;不用碰它。我認爲這是一個問題,我的看法我東陽有:兩個圖像碰撞的問題
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
這裏是代碼:
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
// use the random() function to randomize up our flake attributes
int startY = round(random() % 320);
// set the flake start position
flakeView.center = CGPointMake(490, startY);
flakeView.alpha = 1;
// put the flake in our main view
[self.view addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
// set up how fast the flake will fall
[UIView setAnimationDuration:7 ];
// set the postion where flake will move to
flakeView.center = viewToRotate.center;
// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
我怎樣才能解決這個問題嗎? 如果有人能幫助我,這將是非常酷。
當動畫結束時,將alpha設置爲0.5就足夠了嗎?或者你需要真正的碰撞代碼? – 2011-05-08 08:46:22
我需要真實的碰撞代碼,但是當圖像(flakeView)出現在屏幕上而沒有碰撞另一個is.alpha = 0.5; – 2011-05-08 12:56:09
嗯我仍然不確定你真的需要什麼。所以你有一個片,也許是一個雪片?它從一個隨機的高度(startY)開始並下降,或者去到viewToRotate的位置,對嗎?那麼爲什麼當動畫的目標是讓片狀物位於另一個視圖的相同位置時,您需要碰撞檢測?到目前爲止,這是關於職位,阿爾法與它有什麼關係?當薄片碰到它的最終目的地時,它應該變成半透明的?請幫助我理解。 – 2011-05-08 16:29:21