我有一个UIButton
我附加了UIControlEventTouchUpInside
行动。此按钮插入UIScrollView
。
我的问题是:在我按住按钮一段时间之前,触摸事件将无效。如果我直接点击它,或者只是在模拟器中点击它,它将无法工作。
问题是:当我点击它时,pointInside:withEvent:
实际上已被触发并返回YES
。什么可能阻止事件被解雇?
答案 0 :(得分:0)
尝试将scrollView的delaysContentTouches
属性设置为NO
。
答案 1 :(得分:0)
它应该有效,所以你可以查看以下内容,例如:
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)确保该按钮位于视图堆栈的顶部。为了测试目的,在视图结尾处添加init代码[mybutton bringSubviewToFront];
3)在设备上进行测试,而不仅仅是在模拟器中进行测试。我在模拟器中经历了与在真实设备上不同的滚动/按钮按下行为(这对于测试它更好)。