2014-06-19 88 views
0

我有一組放置在屏幕上的UIImageView。這些圖像視圖中的每一個都有一個標籤,我必須比較它是否是abc命令。每個圖像視圖都附有一個UIPanGesture。它從3開始,如果用戶按照正確的順序獲取它們,它將跳轉到5.問題是持續比較,直到所有(3,5等)圖像視圖都在他們的位置。這讓我瘋狂,因爲我無法弄清楚。確定所有UIPanGestureRecognizer視圖何時完成平移

我需要幫助確定如何確定已移動了多少圖像視圖以及何時完成了所有視圖。

如:3圖像視圖。

當imageView1和imageView2完成平移時,它們將不會執行任何操作,直到imageView3完成平移。到目前爲止,我的代碼只在單個imageView完成平移時起作用。這是下面的代碼。

self.carsLevel是3,5等來自哪裏。

- (void) handlePan:(UIPanGestureRecognizer *)pan 
{ 
if ([pan state] == UIGestureRecognizerStateBegan || [pan state] == UIGestureRecognizerStateChanged) { 
    CGPoint translation = [pan translationInView:[pan.view superview]]; 

    [pan.view setCenter:CGPointMake([pan.view center].x + translation.x, [pan.view center].y + translation.y)]; 
    [pan setTranslation:CGPointZero inView:[pan.view superview]]; 
} 
else { 

    NSString *s1 = self.label1.text; 
    NSString *s2 = self.label2.text; 
    NSString *s3 = self.label3.text; 
    NSString *s4 = self.label4.text; 
    NSString *s5 = self.label5.text; 
    NSString *s6 = self.label6.text; 
    NSString *s7 = self.label7.text; 

    for (int i = 0; i <= self.carsLevel; i++) { 
     if (pan.view.tag == i) { 
      NSLog(@"pan tag = %lu", (unsigned long)pan.view.tag); 
      if (pan.state == UIGestureRecognizerStateEnded) { 
       if (self.carsLevel == 3) { 
        [self compare:s1 to:s2]; 
        [self compare:s2 to:s3]; 
       } 
       else if(self.carsLevel == 5) { 

       } 
       else if(self.carsLevel == 7) { 

       } 
      } 
     } 
    } 
} 
} 

任何幫助表示讚賞!

回答

1

可以沿着這樣的:

else { 
NSInteger carLevels = self.carsLevel; 

if (pan.state == UIGestureRecognizerStateEnded) 
{ 
    ++_countSoFar; // _countSoFar is an iVar 
} 
if (_countSoFar == carLevel) 
{ 
// do what you need to be done 
    _countSoFar = 0; //reset count 
} 
+0

完美。非常感謝! – user2277872

相關問題