我是全新的触摸和拖动,我试图制作八个可拖动的图像。下面是它看起来像在我ViewController.m文件:在iOS中拖动多个图像
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
//check for which peg is touched
if ([touch view] == darkGreyPeg){darkGreyPeg.center = location;}
else if ([touch view] == brownPeg){brownPeg.center = location;}
//there are six more else ifs
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self ifCollided];
}
如果我拿出if语句,以及locationInView:self.view到locationInView:touch.view,我能够左右拖动darkGreyPeg没有问题,并在适当的时候触发我的[ifCollided]。
我正在看一个youTube教程(Milmers Xcode教程,“拖动多个图像”),他有完全相同类型的代码,而我的工作不起作用。任何人都可以向我指出为什么?
谢谢。
你能解释一下吗?我不是个聪明人。 – novalsi