TouchesEnded无法在iOS5中运行,在iOS4中运行良好 [英] TouchesEnded not working in iOS5, working fine in iOS4

查看:129
本文介绍了TouchesEnded无法在iOS5中运行,在iOS4中运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义scrollView,实现了以下方法:

I have a custom scrollView with the following method implemented:

  - (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];

     }
  }

在我的视图控制器中,我有以下方法:

And in My View Controller I have the following method:

-(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;

}

}

,这非常有效,滚动视图的触摸得到识别,touchesEnded在我的视图控制器中被调用,所有这些都与世界一致。但是,在iOS 5x下,touchesEnded永远不会被解雇。有谁知道这是怎么回事?

under iOS 4, this works perfectly, touches on the scrollview are recognized and the touchesEnded gets called in my view controller and all is right with the world. Under iOS 5x, however, the touchesEnded never gets fired. Does anyone know what the heck is going on/wrong?

推荐答案

在这里找到答案,基本上如果你想做我正在做的事你需要将touchesBegan传递给链好吧..因为如果一个viewController没有看到touchesBegan它就不会得到TouchesEnded ...所以我修改了自定义ScrollView以抛出touchesBegan,现在一切正常,5.0

Found the Answer here, basically if you want to do what I am doing you need to pass the touchesBegan up the chain as well.. because if a viewController didn't see the touchesBegan it won't get the TouchesEnded... So I modified the custom ScrollView to throw up the touchesBegan and everything now works fine in 5.0

参考:

UIView触摸处理行为随Xcode 4.2而改变?

这篇关于TouchesEnded无法在iOS5中运行,在iOS4中运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆