简体   繁体   中英

Making multiple objects on screen detect a finger sliding?

My goal here is to get a bunch of squares on the screen to detect a sliding finger, and they will only perform their functions when the square in front of it has been slid over. I was wondering if anyone had any good suggestions or ideas to use? I was thinking I would create an NSMutableArray , using a struct to contain the points for each square, and then wrap the struct in a NSValue then add it to the array. Then I thought I would use a loop to read the array and create all the squares on the screen. But, how do I make the squares detect when a finger slides over them? Do I need to set that in the loop? Does anyone have any suggestions? Sorry, I'm a little new to the iOS game dev. world!

I'm a little confused by your question but I think what you are looking for is the following:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.contentView];

for (UIView *view in self.contentView.subviews)
{
    if ([view isKindOfClass:[MyCustomView class]] &&
        CGRectContainsPoint(view.frame, touchLocation))
    {

    }
}

}

This will detect anytime one of the onscreen objects is touched. If this doesn't address your question please let me know I will try to modify to better address the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM