我有添加 2 个子视图的主视图控制器。
- (void)viewDidLoad
{
[self init];
[super viewDidLoad];
//To shrink the view to fit below the status bar.
self.wantsFullScreenLayout = YES;
//We start off by displaying the background Images.
[self displayMenuSceneBackground];
//Then we show the Menus.
[self displayMenuSceneMenu];
}
这里我们将子视图添加到主视图控制器。两个子视图都是使用界面构建器构建的视图控制器。
-(void) displayMenuSceneBackground{
//Display the MenuSceneBackground View Controller
MenuSceneBackground *screen = [[MenuSceneBackground alloc] init];
[self.view addSubview:screen.view];
[screen release];
}
-(void) displayMenuSceneMenu{
//Display the MenuSceneMenu View Controller
MenuSceneMenu *screen = [[MenuSceneMenu alloc] init];
[self.view addSubview:screen.view];
[screen release];
}
两个子视图都正确显示,即使 MenuSceneBackground 视图控制器中的某些动画也可以正常工作,但是这些子视图都没有接收到触摸事件。
它们都实现了 touchesBegan 但只有主视图控制器接收它们。
我尝试将主视图控制器 userInteraction 设置为 NO,并且没有实现 touchesBegan 方法,但这只会使触摸被忽略。
两个子视图都显示在整个屏幕尺寸上。
我确实读过类似的问题,但回答没有帮助。
我在子视图中有这个
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
NSLog(@"testing MenuSceneMenu");
[self clicked_testing_alert]; //This is a UIAlertView for debugging
return;
}
我在这里先向您的帮助表示感谢。