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

dle*_*ard 6 ios ios5 xcode4.2

我几天前将iPad升级到5.0,同时将Xcode升级到4.2,这样我就可以继续测试我的应用了.现在我在使用以前版本的Xcode的几个应用程序中遇到触摸代码问题.

我将UIImageView子类化为通过覆盖-(void)TouchesBegan和添加一些拖动功能-(void)TouchesMoved.我并没有覆盖-(void)TouchesEnded的子类,但处理的是在包含图像视图的视图视图控制器.

我将子类拉UIImageView入一个新项目进行测试,并将问题缩小到父级UIView(由Xcode创建的模板)似乎不会将触摸事件转发到视图控制器(也由Xcode创建)的事实.

如果我将它添加到我的子类:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touches ended event in ImageToDrag");
    [self.nextResponder touchesEnded:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)

这到我父视图的视图控制器:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touches ended event in ViewController");
}
Run Code Online (Sandbox Code Playgroud)

当我放开图像时,我在屏幕上拖动,我"touches ended event in ImageToDrag"从视图控制器获取,但不是日志.

但是,如果我在子类视图中故意跳过视图:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touches ended event in ImageToDrag");
    [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)

然后我得到两个日志条目.

我能想到的唯一解释是,由于某种原因,UIView消耗touchesEnded事件而不是将其传递给视图控制器.

我已经验证exclusiveTouch设置为NO,并userInteractionEnabled设置YES为父视图和子类UIImageView.

我还测试了iOS 5.0和iOS 4.2的编译,并将测试应用程序部署到iOS 5 iPad和iOS 4.3.1 iPad.

我能够获得触摸事件的唯一方法viewController是跳过视图并nextResponder在子类中使用double .虽然这个方法起作用,但对我来说似乎是一个黑客攻击,我相信它会在以后回来咬我.

有没有人见过这种行为?有什么方法让我知道UIView我的触摸事件正在做什么?

谢谢,丹

Dan*_*eny 5

我一直试图追查过去几个小时的类似问题.终于设法在这篇文章的帮助下解决了这个问题

实际上看起来我只是设法解决它,使用来自https://devforums.apple.com/message/519690#519690的提示
早些时候,我刚刚将touchesEnded事件转发给self.nextResponder.当我添加touchesBegan,Moved,Canceled处理程序与touchesEnded类似的实现时,事件似乎冒泡到根视图控制器.
所以我想在iOS5上,当他们没有看到相关的touchesBegan时,视图会丢弃touchesEnded事件.

我不需要添加Moved/etc.我只是在TouchesBegan上转发,然后TouchesEnded再次开始工作!