Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 将触摸事件重新发送到iOS中的其他视图_Objective C_Ios_Xcode - Fatal编程技术网

Objective c 将触摸事件重新发送到iOS中的其他视图

Objective c 将触摸事件重新发送到iOS中的其他视图,objective-c,ios,xcode,Objective C,Ios,Xcode,我在UIScrollView上有一个UIImageView(而不是其中的一个元素)。嗯,我已经对UIImageView进行了子类化,以检查触摸事件,并覆盖了touchsbegind:withEvent:方法。在该方法中,我基本上在UIScrollView元素后面发送子类UIImageView。(我使用[self.super-bringsubview-tofront:scrollView]来实现这一点) 我想要的是能够将UIImageView的当前触摸事件发送到UIScrollView元素,这样用

我在
UIScrollView
上有一个
UIImageView
(而不是其中的一个元素)。嗯,我已经对
UIImageView
进行了子类化,以检查触摸事件,并覆盖了
touchsbegind:withEvent:
方法。在该方法中,我基本上在
UIScrollView
元素后面发送子类
UIImageView
。(我使用
[self.super-bringsubview-tofront:scrollView]
来实现这一点)

我想要的是能够将
UIImageView
的当前触摸事件发送到
UIScrollView
元素,这样用户就不必抬起手指再次触摸才能滚动。我已经尝试在
UIScrollView
元素上调用
touchsbegind:withEvent:
,但没有任何效果

有没有人知道应该怎么做,以便我可以模拟
UIImageView
UIScrollView
元素的接触

下面是子类
UIImageView
中被重写的方法:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
     [super touchesBegan: touches withEvent: event];

     ViewController* controller = [Singleton getSingleton].controller;
     [super bringSubviewToFront: controller.scrollView]; //Now scroll view is in the front

     [controller.scrollView touchesBegan: touches withEvent: event]; //Does nothing
}

我需要覆盖
UIImageView
子类中的
hitTest:withEvent:

(UIView*) hitTest: (CGPoint)point withEvent: (UIEvent*)event
{
    if([self pointInside:point withEvent:event]){
         ViewController* controller = [Singleton getSingleton].controller;
         [controller.view bringSubviewToFront: controller.scrollView];
         return controller.scrollView;
    }else{
         return [super hitTest:point withEvent: event];
    }
}

这样,当点击
UIImageView
时,它会首先调用这个方法,将
UIScrollView
放在前面,然后返回
UIScrollView
作为应该处理事件的对象,但是由于您的触摸事件已经开始,所以我认为新事件没有意义,当您将scrollview置于顶部时,TouchsMoved是否会被解雇?您希望实现什么?您只需通过设置
userInteractionEnabled=NO
(默认设置为
UIImageView
)使UIImageView非触摸敏感即可。@propstm将滚动视图置于顶部后不会滚动。我没有覆盖touchesMoved方法。我不重写UIScrollView,但它不会滚动。@fzwo我想要实现的是UIScrollView顶部的UIImageView。当触摸UIImageView时,UIScrollView被带到前面,并使用相同的手指触摸滚动,但目前没有发生这种情况。