我有一个视图和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;
}
}
答案 0 :(得分:1)
您是否尝试过使用视图标签?您可以为每个视图设置标记。 if(touch.view.tag == viewPushDatumTag)// viewPushDatumTag可能是#define
答案 1 :(得分: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;
}
}
这对我有用。谢谢