I am using touchBegin and touchMoved in my app.
i am setting array of uiview in the screen:
UIView *white = [[UIView alloc]initWithFrame:CGRectMake(x, y, widSize, heiSize)];
[white setBackgroundColor:[UIColor whiteColor]];
[whites addObject:white];
[self.view addSubview:white];
of course they are in the screen and i can see it(i do it in loop)
now, i put toch begin method and what it do it only tell me which uiview was pressed.
i want to do the same thing with touchedMoved and recognize if user drag is finger on the screen:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray* touchArray = [touches allObjects];
for (int i = 0; i < [touchArray count]; ++i) {
UITouch* touch = [touchArray objectAtIndex:i];
UIView *key = [touch view];
int i = [whiteKeys indexOfObject:key];
if (i > 7) {
int j = [whiteKeys indexOfObject:key];
NSLog(@"%d",j);
continue;
}
NSLog(@"%d",i);
}
}
the problem is that when i moved my finger on the screen, he print me always the number of the view i pressed the screen in the start and not change it although i moved my finger on another uiview
This is a core concept of touch handling in iOS. The touches always belong to the view they started in – not the view that they move to during a touch. I would HIGHLY recommend watching the video on multi-touch from WWDC 2011 (one of the best of the conference) which goes into all of this in detail:
https://developer.apple.com/itunes/?destination=adc.apple.com.8270634034.08270634040.8367260921?i=1527940296