我創造抽屜
self.isShowMenuVC = NO;
_menuView = [MenuViewController viewController];
[self.menuView setDelegate:self];
[self addChildViewController:self.menuView];
[self.menuView.view setFrame:CGRectMake(-kMenuTableWidth, 0, kMenuTableWidth, self.view.frame.size.height)];
[self.view addSubview:self.menuView.view];
[self.menuView didMoveToParentViewController:self];
UITapGestureRecognizer *outsideTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(outsideTapped:)];
[self.view addGestureRecognizer:outsideTap];
outsideTap.delegate = self;
,當按鈕自來水我剛纔設置的_menuView.view
幀像一個抽屜
我想是來檢測觸摸外面的抽屜,但我不能這樣做
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (touch.view == self.menuView.view) {
NSLog(@"Touch Drawer");
} else {
NSLog(@"Touch Outside");
}
return YES;
}
但它始終顯示觸摸外」
我思念的東西,但不知道該怎麼感謝事先
與2的姿勢也可以嘗試,但沒有工作,因爲在self.view一個手勢所以,當我點擊抽屜方法調用2次。
對於我試圖禁用一個手勢,仍然調用兩次
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (gestureRecognizer == self.touchInDrawer) {
NSLog(@"Touch in drawer");
[self.touchOutSideDrawer setEnabled:NO];
} else {
NSLog(@"Outside");
[self hideMenuView];
}
return YES;
}
我試過不工作,因爲我在self.view中添加了手勢,所以當我點擊抽屜手勢委託方法觸發2次 –
嘗試實現委託的方法: - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeShultaneouslyWithGestureRecognizer :(UIGestureRecognizer *)otherGestureRecognizer 並且僅僅返回NO; –
也嘗試實施方法: - (BOOL)gestureRecognizerShouldBegin :(UIGestureRecognizer *)gestureRecognizer –