0
我有parentView
和子視圖childView
。 childView
位於我的parentView
的中間,大小隻有它的一半。如果用戶點擊parentView
,我想關閉childView
。當父視圖被觸摸時關閉子視圖
一旦childView
處於打開狀態,我的代碼將在parentView
中創建一個UITapGestureRecognizer
。
我的問題是,當用戶觸摸任何視圖時觸發輕擊事件,而不僅僅是parentView
。
因此,我想知道如何才能讓事件發生,如果只有父視圖被觸摸或任何其他可能關閉子視圖,如果父母被觸摸。
- (IBAction)selectRoutine:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
createRoutinePopupViewController* popupController = [storyboard instantiateViewControllerWithIdentifier:@"createRoutinePopupView"];
popupController.view.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
_ass = popupController;
//Tell the operating system the CreateRoutine view controller
//is becoming a child:
[self addChildViewController:popupController];
//add the target frame to self's view:
[self.view addSubview:popupController.view];
//Tell the operating system the view controller has moved:
[popupController didMoveToParentViewController:self];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singleTap setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:singleTap];
}
-(void) handleSingleTap: (id) sender {
NSLog(@"TEST STRING");
}
它說objView是undefined? – 2013-05-04 13:30:42
顯然它應該說,因爲你需要替換它的父視圖的對象 – HarshIT 2013-05-04 13:31:57
希望你在頭文件中添加了並且還分配了singleTap.delegate = self; –
HarshIT
2013-05-04 13:34:18