我有主视图控制器,它添加了 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,并且不实现 TouchBegan 方法,但这只会使触摸被忽略。
两个子视图都显示在整个屏幕尺寸上。
我确实读过类似的问题,但回复没有帮助。
我在子视图中有这个
- (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;
}
我在这里先向您的帮助表示感谢。
请注意,UIViewController 与 UIView 不同,因此不会接收 TouchBegan 事件。 (您在视图控制器而不是视图中添加了touchesBegan...)。
Solution:感谢 Simon Goldeen,我发现在演示项目中,touchesBegan 被调用。然而,在我的制作项目中,情况并非如此。事情是这样的:(按照苹果的建议)你和我正在使用- (void)release;
以减少内存使用。 这会导致不调用touchesBegan。西蒙不使用release
,所以在他的情况下,他们确实会接到电话。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)