我无法从具有UIButton
子视图的UIView
捕获触摸事件。 UIButton
可能会阻止touchesBegan
和touchesEnd
事件到达外部视图。
如何处理这些事件?我尝试将UserInteractionEnabled
设置为 false。触摸事件到达外部视图,但UIButton
不会在此解决方案中转换为突出显示状态。
有没有办法在不丢失按钮自然行为的情况下完成此操作?
(附言我不想使用手势识别器等,因为我需要获取事件的实际时间戳(
如果我理解了你的问题,你可以试试这种方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
if (CGRectContainsPoint(yourbutton.frame, [touch locationInView:self])) { //if touch is beginning on Button
}
}