0

我有一个视图和 3 个其他视图,但只有 viewPushDatum 视图与我的问题相关。当 viewPushDatum 在屏幕上并且我点击它的任意位置时,什么都不会发生,并且工作正常,但是我在 viewPushDatum 上也有一个 UIDatePicker,当我单击该视图时,该视图消失了。我有一个 UIGestureRecognizer 应该隐藏我的 viewPushDatum 但我只想在单击此视图之外的某处时隐藏 viewPushDate。我尝试将 touch.view == myUIDatePicker 添加到下面的函数中,但这不起作用,我尝试了 touch.accessibilityFrame 但我没有让它工作。有谁知道如何更改代码以便仅在我的 viewPushDatum 之外调用gestureRecognizer?

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    if (touch.view == viewPushDatum) {
        return NO;
    } else {
        return YES;
    }
}
4

2 回答 2

1

您是否尝试过使用视图标签?您可以为每个视图设置标签。if (touch.view.tag == viewPushDatumTag) // viewPushDatumTag 可以是#define

于 2013-11-04T22:02:32.163 回答
0
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

UIView *pushDatumView;
if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
    //iPhone 5
    pushDatumView = [[UIView alloc]initWithFrame:CGRectMake(0, -224+568, 320, 224)];


} else if ((int)[[UIScreen mainScreen] bounds].size.height == 480) {
    //iPhone 4
    pushDatumView = [[UIView alloc]initWithFrame:CGRectMake(0, -224+480, 320, 224)];
}

CGPoint aPoint = [touch locationInView:viewPushDatum];
BOOL isPointInsideView = [pushDatumView pointInside:aPoint withEvent:nil];


if (isPointInsideView == TRUE) {
    return NO;
} else {
    return YES;
}
}

这现在对我有用。不过谢谢

于 2013-11-06T21:08:49.323 回答