繁体   English   中英

父UIScrollView检测子UIView的触摸

[英]Parent UIScrollView detecting child UIView's touches

基本上...

我有一个UIScrollView子类,您也可以添加目标和选择器,如果在视图中检测到触摸事件,则会触发该目标和选择器。 我使用滚动视图作为图库,并且滚动视图内部的触摸用于淡出HUD组件(UItoolBar等):

@implementation TouchableScrollView

- (void)addTarget:(id)_target withAction:(SEL)_action
{
    target = _target;
    action = _action;
    shouldRun = NO;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    shouldRun = YES;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    shouldRun = NO;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(shouldRun)
    {
        shouldRun = NO;
        [target performSelector:action];
    }
}

@end

然后,我添加了另一个自定义UIView作为对此的子视图,该视图具有以下设置(我都玩过这两个设置):

self.userInteractionEnabled = YES;
self.exclusiveTouch = YES;

并使用以下代码触发动画:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

问题是,即使自定义UIView检测到触摸并做出响应(通过将自身翻转过来),也会触发UIScrollView选择器,从而使所有内容淡出。

请帮忙,我完全被困住了吗?

最好在自定义ScrollView类中使用它

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if (!self.dragging) { [self.nextResponder touchesEnded: touches withEvent:event]; }
[super touchesEnded: touches withEvent: event];

self.nextResponder是scrollView的子视图。 因此,除了拖动(滚动)之外的其他事件将由您的主viewController处理。 在主View控制器中继承触摸事件方法。 您可以在那里查看特定视图或图像视图的触摸事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM