Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.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
Objective c 子视图中的手势识别器有问题_Objective C_Ios_Uigesturerecognizer - Fatal编程技术网

Objective c 子视图中的手势识别器有问题

Objective c 子视图中的手势识别器有问题,objective-c,ios,uigesturerecognizer,Objective C,Ios,Uigesturerecognizer,我有一个相当基本的问题,我环顾四周(这里,谷歌,等等),还没有找到解决这个问题的方法: 在我的视图控制器的viewDidLoad中,我有: UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(myfunc:)]; //I have a UIScrollView named "containerView" //her

我有一个相当基本的问题,我环顾四周(这里,谷歌,等等),还没有找到解决这个问题的方法:

在我的视图控制器的
viewDidLoad
中,我有:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(myfunc:)];

//I have a UIScrollView named "containerView"
//here's some code that creates an UIView in a variable named "myView"

//this works fine, I can see "myView" when I run it
[containerView addSubview:myView];

[myView addGestureRecognizer:longPress];
然后我在同一个类中有这个函数:

- (void)myfunc:(UIRotationGestureRecognizer *)recognizer 
{
    NSLog(@"hola!"); //never runs
}
NSLog
的调用从未运行。我做错了什么

编辑

一些额外信息:似乎从未向子视图发送任何触摸事件。但是,我尝试添加一个内部带有按钮的UIView,所有这些都在UIScrollView中,按钮接收触摸事件的效果很好,因此问题只存在于以编程方式添加的子视图中。

TLDR:

在将手势识别器添加到滚动视图时执行此操作

也调查

[containerView setDelaysContentTouches:NO];
如果上述行为不完全正确

有关更多信息:

奇怪的是,在UIScrollView中添加了一个“容器”UIView,然后在该容器中添加了其他子视图,使其能够工作。现在,触摸事件被发送到子视图。

我认为在myFunc上,您必须执行以下操作:

switch (reconiger.state)
{
    case UIGestureRecognizerBegin:
      //Do something when start recognizer
      break;
    case UIGestureRecognizerEnd:
      //Do something when end recognizer
      break;
}

你试过长时间按屏幕吗?好吧,这就是所有这些的重点,不是吗..我想是的:)只是到处乱动^^不管怎样,你的代码看起来很完美。也许你可以1。在将视图添加为子视图之前添加识别器;2.将其特别插入任何其他视图的顶部,以便其他视图无法拦截其触摸事件。我尝试了#1,没有运气。但是,我尝试在视图中添加一个圆形Rect按钮,但它似乎对触摸没有反应。。。知道为什么会发生这种情况吗?我玩过那些东西,它们没有帮助。看看我对这个问题的编辑,我在界面编辑器上手动添加了一个子视图,它接收触摸事件,但不是我以编程方式添加的子视图。。。
switch (reconiger.state)
{
    case UIGestureRecognizerBegin:
      //Do something when start recognizer
      break;
    case UIGestureRecognizerEnd:
      //Do something when end recognizer
      break;
}