简体   繁体   English

使屏幕上的多个对象检测到手指滑动?

[英]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. 我当时在想创建一个NSMutableArray ,使用一个结构包含每个正方形的点,然后将该结构包装在NSValue然后将其添加到数组中。 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. 抱歉,我是iOS游戏开发者的新手。 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 如果这不能解决您的问题,请告诉我,我将尝试进行修改以更好地解决该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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