我明白如何製作可拖動的圖像,但是我無法從類文件中將圖像從我的主ViewController.m文件中拖出。我的班級被稱爲「炸彈」。每兩秒鐘,一個新的炸彈被創造出來,並帶着一個炸彈圖像(一個炸彈的對象)。炸彈被添加到NSMutableArray(bombArray)。從類文件中拖拽圖像
- (void) newBomb
{
bomb *bomb1 = [[bomb alloc] init];
[bombArray addObject: bomb1];
[bomb1 displayBombOnView:self.view]; //displayBombOnView just makes a new bomb in a random location
}
我試圖讓用戶可以拖動每個「炸彈」。
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event : (bomb *) bomb
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
bomb->bombImage.center = location;
}
-(void) touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event
{
bomb *tempBomb = [[bomb alloc] init];
arrayCount = [bombArray count];
for (int k = 0; k<arrayCount; k++)
{
tempBomb = [bombArray objectAtIndex:k];
CGPoint tappedPt = [[touches anyObject] locationInView: self];
int xPos = tappedPt.x;
int yPos = tappedPt.y;
if ((xPos >= tempBomb->bombImage.center.x - 25 && xPos <= tempBomb->bombImage.center.x + 25) && (yPos >= tempBomb->bombImage.center.y - 25 && xPos <= tempBomb->bombImage.center.y + 25))
{
[self touchesBegan:touches withEvent:event : [bombArray objectAtIndex:k]];
break;
}
}
}
它建立,但後來當我試圖拖動圖像,它崩潰,說Thread 1: signal SIGABRT
。任何幫助將不勝感激。
嘗試設置異常斷點以查看應用程序崩潰的特定行嗎? –
您可以設置捕獲所有異常。如需幫助,請閱讀:http://www.learningipadprogramming.com/2011/12/10/breakpoint-on-all-exceptions/ – stosha