1
我無法弄清楚爲什麼會發生這種情況,但我有一個UIView的子類添加到我的視圖控制器的視圖中。子視圖在父視圖中接收到其外框之外的觸摸
productView = [[SKUProductView alloc]initWithFrame:CGRectMake(60,768, 700, 550)];
[self.view addSubview:productView];
的視圖開始離屏和將屏幕上的動畫平移姿勢event.While視圖是離屏,它正在接收其自己的框架的外側的觸摸事件。我開發了一個工具,通過覆蓋子視圖中的hitTest方法,以便在觸摸事件超出其框架的情況下將hitTest調用返回到超級視圖。
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
//Test to determine if view is offscreen or if touch is outside its frame
if (self.frame.origin.y >= 768 || point.x > self.frame.size.width)
{
return [super hitTest:point withEvent:event];
}
else if (point.y < kSKU_SCROLLVIEW_Y_OFFSET)
{
return [_productTabBar hitTest:point withEvent:event];
}
return _productScrollView;
}
但我不知道爲什麼我的子視圖接收到它自己的框架外的觸摸事件擺在首位?
您是在故事板還是在代碼中設置UIPanGesture識別器?你可以發佈代碼,如果你以編程的方式嗎? – tanzolone