Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
Iphone UIButton TouchUpInside未被激发,但pointInside:withEvent:返回YES_Iphone_Cocoa Touch_Uibutton - Fatal编程技术网

Iphone UIButton TouchUpInside未被激发,但pointInside:withEvent:返回YES

Iphone UIButton TouchUpInside未被激发,但pointInside:withEvent:返回YES,iphone,cocoa-touch,uibutton,Iphone,Cocoa Touch,Uibutton,我有一个ui按钮,上面附加了UIControlEventTouchUpInside操作。此按钮插入到UIScrollView中 我的问题是:按住按钮一段时间后,触摸事件才会生效。如果我直接点击它,或者只是在模拟器中点击它,它将无法工作 问题是:当我点击它时,pointInside:withEvent:实际上被触发并返回YES。什么可能阻止事件被触发?尝试将scrollView的延迟内容切换属性设置为否它应该可以工作,以便您可以检查以下内容,例如: 1) 确保您的按钮已正确添加到scrollvie

我有一个
ui按钮
,上面附加了
UIControlEventTouchUpInside
操作。此按钮插入到
UIScrollView

我的问题是:按住按钮一段时间后,触摸事件才会生效。如果我直接点击它,或者只是在模拟器中点击它,它将无法工作


问题是:当我点击它时,
pointInside:withEvent:
实际上被触发并返回
YES
。什么可能阻止事件被触发?

尝试将scrollView的
延迟内容切换
属性设置为
它应该可以工作,以便您可以检查以下内容,例如:

1) 确保您的按钮已正确添加到scrollview。例如:

    ...
    myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    myScrollView.bounces = NO;
    [myScrollView setScrollEnabled:YES];
    myScrollView.showsHorizontalScrollIndicator = NO;
    myScrollView.delegate = self;
    myScrollView.pagingEnabled = YES;
    [self.view addSubview:myScrollView];
    myScrollView.contentSize = CGSizeMake(320*5, 480);
    ...
    UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeCustom];
    mybutton.frame = CGRectMake(0,0,100,100);
    mybutton.tag = 1
    [mybutton addTarget:self action:@selector(pressedmybutton:) 
          forControlEvents:UIControlEventTouchUpInside];
    [myScrollView addSubview:bu];
2) 确保该按钮位于视图堆栈的顶部。出于测试目的,在视图初始化代码的末尾添加[mybutton bringSubviewToFront]


3) 在设备上测试,而不仅仅是在模拟器上。我在模拟器中体验到与在真实设备上不同的滚动/按钮按下行为(这是最好的测试方法)。

是否有其他视图可能在触摸事件到达
UIButton
之前在中更高,消耗触摸事件?