Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 将UIView更改为UIScrollView后,触摸移动不再触发?_Xcode_Uiview_Uiscrollview_Touchesmoved - Fatal编程技术网

Xcode 将UIView更改为UIScrollView后,触摸移动不再触发?

Xcode 将UIView更改为UIScrollView后,触摸移动不再触发?,xcode,uiview,uiscrollview,touchesmoved,Xcode,Uiview,Uiscrollview,Touchesmoved,我有一个有很多东西的UIView。我还有一个触摸屏的实现,如下所示: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"move"); } #import "AppScrollView.h" @implementation AppScrollView - (id)initWithFrame:(CGRect)frame { return [super initWithFrame

我有一个有很多东西的UIView。我还有一个触摸屏的实现,如下所示:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"move");
}
#import "AppScrollView.h"

@implementation AppScrollView

- (id)initWithFrame:(CGRect)frame
{
    return [super initWithFrame:frame];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesEnded:withEvent:");

    // If not dragging, send event to next responder
    if (!self.dragging)
        [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesMoved:withEvent:");

    [[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];
}

@end
2013-06-11 10:45:21.625 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.625 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.655 Test[54090:c07] AppScrollView touchesEnded:withEvent:
2013-06-11 10:45:21.656 Test[54090:c07] SomeClass touchesEnded:withEvent:
我最近想让视图滚动,所以我只是打开UIView,在Interface Builder中将其对象类更改为UIScrollView。但是,现在,即使我触摸屏幕,也不会调用“touchesMoved”方法

有人能帮我重新开始工作吗?我不知道我是怎么打破它的

编辑:我试着跟随,但我可能做错了什么。从阅读其他帖子来看,UIScrollView似乎无法接受触摸事件本身,它们需要发送到响应者链上?我将非常感谢任何能帮助我解决这个问题的人。。。当我意识到UIScrolView扼杀了我的触摸检测时,我的应用程序正准备提交!(我刚刚将我的应用程序UIView更改为UIScrollView,以允许与iPhone 4兼容)。

我刚刚查看了您的编辑,我想我可以看到问题所在。关于类似的问题,请参见

您的
UIScrollView
子类将如下所示:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"move");
}
#import "AppScrollView.h"

@implementation AppScrollView

- (id)initWithFrame:(CGRect)frame
{
    return [super initWithFrame:frame];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesEnded:withEvent:");

    // If not dragging, send event to next responder
    if (!self.dragging)
        [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesMoved:withEvent:");

    [[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];
}

@end
2013-06-11 10:45:21.625 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.625 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.655 Test[54090:c07] AppScrollView touchesEnded:withEvent:
2013-06-11 10:45:21.656 Test[54090:c07] SomeClass touchesEnded:withEvent:
包含
AppScrollView
对象的类应采用
UIScrollViewDelegate
协议并实现以下方法:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"SomeClass touchesMoved:withEvent:");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"SomeClass touchesEnded:withEvent:");
}
然后,记录的输出将如下所示:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"move");
}
#import "AppScrollView.h"

@implementation AppScrollView

- (id)initWithFrame:(CGRect)frame
{
    return [super initWithFrame:frame];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesEnded:withEvent:");

    // If not dragging, send event to next responder
    if (!self.dragging)
        [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesMoved:withEvent:");

    [[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];
}

@end
2013-06-11 10:45:21.625 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.625 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.655 Test[54090:c07] AppScrollView touchesEnded:withEvent:
2013-06-11 10:45:21.656 Test[54090:c07] SomeClass touchesEnded:withEvent:

你的问题看起来很像。也许其中一个建议对你有用?谢谢你的链接。他们建议设置mainScroller.delaysContentTouches=NO;和_mainScroller.canCancelContentTouches=NO;我已经做了这两件事,我的触摸仍然没有被检测到。非常感谢你的回复。。。今天下班后我会试试看,然后回来汇报!嗯。它起作用了。虽然只有一个nextResponder调用,但它不起作用。知道为什么吗?