2015-07-02 26 views
0

我試圖計算何時出現左滑動操作。然而,對於代碼我迄今爲止的結果總是1.iOS - 計數滑動

任何想法爲什麼?

- (void)handleSwipes:(UISwipeGestureRecognizer *)sender 
{ 
    int countLeft = 0; 

    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) 
    { 

     countLeft += 1; 
     imagesequence = @"2.png"; 
     [_MainBackground setImage:[ UIImage imageNamed: imagesequence]]; 

     NSLog(@"LEFT = %d", countLeft); 
    } 


    if (sender.direction == UISwipeGestureRecognizerDirectionRight) 
    { 
     NSLog(@"RIGHT"); 
     imagesequence = @"3.png"; 
     [_MainBackground setImage:[ UIImage imageNamed: imagesequence]]; 
    } 
} 
+0

如果您將代碼顯示在您設置GestureRecognize及其代表的位置,這對您會有幫助,因此我們可以看到您是如何定義手勢識別器的。另外,向我們展示如何/在哪裏定義countLeft ...是否與@synthesize語句或什麼有關? – sunny

回答

1

的問題是,int countLeft = 0;如此每次運行時,countLeft定義並初始化爲0方法範圍內的定義,你需要促進該範圍較廣,以保持最新的執行值(移動定義外部方法)。

+0

非常感謝你..只是在虛空之外移動int ..作品很棒 – SNos