Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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
Ios 向UIScrollView中的标准平移手势识别器添加功能_Ios_Uiview_Uiscrollview_Uigesturerecognizer - Fatal编程技术网

Ios 向UIScrollView中的标准平移手势识别器添加功能

Ios 向UIScrollView中的标准平移手势识别器添加功能,ios,uiview,uiscrollview,uigesturerecognizer,Ios,Uiview,Uiscrollview,Uigesturerecognizer,我正在尝试跟踪手指在UIScrollView中的位置。 我已经将UIScrollView(见下文)子类化,但不幸的是,我添加的手势识别器正在覆盖标准的手势识别器 因此,我可以使用NSLog(@“Pan”),但不幸的是,视图不再滚动 如何使两个手势识别器同时工作 谢谢 - (void)viewDidLoad:(BOOL)animated { [super viewDidLoad:animated]; UIPanGestureRecognizer *panRecognizer =

我正在尝试跟踪手指在
UIScrollView
中的位置。 我已经将
UIScrollView
(见下文)子类化,但不幸的是,我添加的手势识别器正在覆盖标准的手势识别器

因此,我可以使用
NSLog(@“Pan”)
,但不幸的是,视图不再滚动

如何使两个手势识别器同时工作

谢谢

- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad:animated];

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    [scrollView addGestureRecognizer:panRecognizer];
}


- (void)pan:(id)sender {
    NSLog(@"Pan");
}

编辑:此方法有效!您只需尽快设置
canCancelContentTouches
(我在
viewDidLoad
中进行设置)

原始答案:我尝试了一种新方法,但不幸的是,它没有完全起作用

我没有添加手势识别器,而是将
UIScrollView
子类化,并编写自己的
touchesBegind
touchesMoved
等方法

通过这种方式,我知道用户触摸的位置,但不幸的是,即使在将
canCancelContentTouches设置为NO之后,每次我开始滚动时,PangestureRecognitor都会触发
touchesCancelled


有人知道为什么吗?我也发现了。

如果你不想让它覆盖标准,你只需要允许两者同时被识别

- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad:animated];

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    panRecognizer.delegate = self;
    [scrollView addGestureRecognizer:panRecognizer];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
     return TRUE;
}


- (void)pan:(id)sender {
    NSLog(@"Pan");
}

当两件事同时发生时,你不会说你期望发生什么。您希望它滚动并更新您的pan识别器吗?如果是这样的话,为什么不听听滚动视图时调用的滚动视图委托方法呢?我希望视图能够滚动并记录所有接触的点(我知道我可以通过
locationInView:
方法检索这些点)。滚动视图代理听起来很有趣-我从来没有听说过。。。我对iOS编程还很陌生,这是怎么回事?谢谢。我已经找到了,但我不知道如何检索触摸的坐标。