2012-07-07 40 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?

相关问题