可能重複:
Generating Random Numbers in Objective-CCGPointMake(隨機(),隨機())不工作
嗨,我創建就是當你按下一個疙瘩再轉移到一個隨機的應用放置在視圖中。疙瘩是UIImageView。下面是我把中的代碼:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:pimple];
if (CGRectContainsPoint(pimple.bounds, point)) {
[self checkcollision];
}
}
-(void)checkcollision
{
pimple.center = CGPointMake(random(), random());
sad.hidden = NO;
NSURL* popURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pop" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((CFURLRef) popURL, &popID);
AudioServicesPlaySystemSound(popID);
}
此代碼:pimple.center = CGPointMake(隨機(),隨機());不起作用。當我按下疙瘩時,疙瘩消失。由於我沒有提到任何隱藏的疙瘩,它必定意味着它在移動。但是你不能看到它(它在視圖外部)。我的代碼有什麼問題嗎?我錯過了什麼嗎?請幫忙。