I'm a beginner in learning objective c. I want to make my iphone app do this thing:
- if touch A area, do XXXXX
- if touch B area, do YYYYY
- if touch A&B areas at same time, do ZZZZZZ
I think the first thing I need to do is to save the Coordinate of every touch, and then to check all the coordinates in the right area or not.
I Use NSMutableArray to save the Coordinate, but I don't know how to get the content in the array.
Here is my code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableArray *Xarray;
NSMutableArray *Yarray;
Xarray=[NSMutableArray arrayWithCapacity:[touches count]];
Yarray=[NSMutableArray arrayWithCapacity:[touches count]];
for(UITouch *touch in touches)
{
CGPoint pstart=[touch locationInView:self.view];
[Xarray addObject:[NSNumber numberWithFloat:pstart.x]];
[Yarray addObject:[NSNumber numberWithFloat:pstart.y]];
}
}
thanks very much!
touchesBeginmethod? I think your solution will be expensive anyway, creating and populating an object each time the screen is touched (not to mention what looks like a memory leak usingarrayWithCapacityrather thaninitWithCapacity).