我在UIImageView
之上(而非元素)UIScrollView
。好吧,我已经将UIImageView
子类化为检查触摸事件并覆盖了touchesBegan:withEvent:
方法。在该方法中,我基本上在UIImageView
元素后面发送了子类UIScrollView
。 (我使用[self.super bringSubviewToFront: scrollView]
来实现这一目标。)
我想要的是能够将UIImageView
的当前触摸事件发送到UIScrollView
元素,这样用户就不必抬起手指再次触摸滚动。我已经尝试在touchesBegan:withEvent:
元素上调用UIScrollView
,但它什么也没做。
有没有人知道该怎么做才能模拟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
}
答案 0 :(得分:3)
我需要覆盖hitTest:withEvent:
子类中的UIImageView
。
(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
作为对象返回应该处理这个事件。