2012-07-07 37 views
2

我有一個自定義的滾動視圖以實現以下方法:TouchesEnded不是在iOS5的工作,做工精細的iOS4的

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //if not dragging send it on up the chain 
    if(!self.dragging){ 
    [self.nextResponder touchesEnded:touches withEvent:event]; 
    }else { 
     [super touchesEnded:touches withEvent:event]; 

    } 
    } 

而且在我的視圖控制器我有以下方法:

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


NSLog(@"TOUCH"); 
//---get all touches on the screen--- 

NSSet *allTouches = [event allTouches]; 



//---compare the number of touches on the screen--- 

switch ([allTouches count]) 

{ 

     //---single touch--- 

    case 1: { 

     //---get info of the touch--- 

     UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; 



     //---compare the touches--- 

     switch ([touch tapCount]) 

     { 

       //---single tap--- 

      case 1: { 
       NSLog(@"Single"); 

       [self mySingleTapMethod]; 
      } break; 



       //---double tap--- 

      case 2: { 

       [self myDoubleTapMethod]; 
      } break; 

     } 

    } break; 

} 

}

在iOS 4下,這個功能完美,觸動scrollview被識別,並且touchesEnded在我的視圖控制器中被調用,並且與世界一切都是正確的。然而,在iOS 5x下,touchesEnded永遠不會被解僱。有誰知道這是什麼事?/錯?

+0

在iOS 5中的問題似乎涉及到叫出了滾動型從未到達ViewController中的touchesEnded。scrollView中的touchesEnded確實被觸發。 – user282172 2012-07-07 17:58:42

回答

3

在這裏找到答案,基本上如果你想做我正在做的事情,你需要傳遞touchesBegin鏈以及..因爲如果一個viewController沒有看到touchesBegan它不會得到TouchesEnded。 ..所以我修改自定義滾動型扔了的touchesBegan,現在一切都在正常工作5.0

參考:

UIView touch handling behavior changed with Xcode 4.2?

相關問題