Ios 避免同时按下2个视图控制器

Ios 避免同时按下2个视图控制器,ios,objective-c,uiimageview,frame,touches,Ios,Objective C,Uiimageview,Frame,Touches,在我的应用程序设置中,我有一个带有4个图像视图的导航控制器。其中1个可以拖动,而其他3个固定在视图的顶部。使用下面的代码,我将其设置为用户将一个图像视图拖动到他想去的地方的图像视图。为了得到视图1,他将活动图像视图拖动到图像视图1,以此类推。问题在于,随着图像视图的宽度,选择器视图可能一次触摸两个,这会产生嵌套视图控制器问题。有没有一种方法可以避免这种情况的发生,除了将图像视图移动得太远以至于一次无法选择多个图像视图之外 - (void)touchesMoved:(NSSet *)touches

在我的应用程序设置中,我有一个带有4个图像视图的导航控制器。其中1个可以拖动,而其他3个固定在视图的顶部。使用下面的代码,我将其设置为用户将一个图像视图拖动到他想去的地方的图像视图。为了得到视图1,他将活动图像视图拖动到图像视图1,以此类推。问题在于,随着图像视图的宽度,选择器视图可能一次触摸两个,这会产生嵌套视图控制器问题。有没有一种方法可以避免这种情况的发生,除了将图像视图移动得太远以至于一次无法选择多个图像视图之外

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    // If the touch was in the placardView, move the placardView to its location
    if ([touch view] == clock) {
        CGPoint location = [touch locationInView:self.tabBarController.view];
        clock.center = location;
        BOOL isIntersecting = CGRectIntersectsRect(clock.frame, prayer.frame);
        BOOL isIntersecting2 = CGRectIntersectsRect(clock.frame, fasting.frame);
        BOOL isIntersecting3 = CGRectIntersectsRect(clock.frame, study.frame);

        if(isIntersecting){
            [self schedulePrayer];
            NSLog(@"prayer");
        }
        if(isIntersecting2){
            [self scheduleFasting];
            NSLog(@"fasting");
        }
        if(isIntersecting3){
            [self scheduleStudying];
            NSLog(@"Studying");
        }
        return;
    }
}
创建另一个BOOL“isTouching”并使其全球化。然后在if(isIntersecting)中,将“ISTOUCH”设置为全局,并添加“ISTOUCH”作为条件,以便:

if ([touch view] == clock && (!isTouching)) 
如果UIImageView不在任何相交视图上,您还需要将ISTOUCH设置为false,这样您就可以开始了:)


这对你解决问题来说应该是足够的提示,但是如果你想得到更多的澄清,请告诉我。

如果。。。否则如果。。。如果,还有其他原因吗

 if(isIntersecting){
            [self schedulePrayer];
            NSLog(@"prayer");
        }
 else if(isIntersecting2){
            [self scheduleFasting];
            NSLog(@"fasting");
        }
 else if(isIntersecting3){
            [self scheduleStudying];
            NSLog(@"Studying");
        }

然后,一次只能触发一个。

真可惜。因为我刚刚在XCode中尝试了确切的场景,我的解决方案很好。但既然你已经投了反对票,我就不想进一步解释了。对不起,如果你要花时间回答一个问题,也许回答这个问题时不要说“这应该足够了”。我没有发帖希望得到提示。就像我说的,你的答案不应该包含“这应该足够提示”这句话。这让读者认为你是完美的,什么都知道,而且非常谦逊。你为什么不使用if。。。否则如果。。。否则呢?然后一次只触发一个。如果你将此作为答案发布,@Ricky我将接受它。按要求发布。谢谢