[英]UIButton not receiving touches when added to subview, but does when added to main view
Basically I have a main screen that comes up with a background image and three menu choices across the bottom of the screen. 基本上,我有一个主屏幕,上面带有背景图像和屏幕底部的三个菜单选项。 When I add these 4 components to the RootViewController's view, everything works fine., but if I do something like 当我将这4个组件添加到RootViewController的视图中时,一切正常,但是如果我做类似的事情
_mainContainer = [[UIView alloc] init];
self.view = _mainContainer;
_firstScreen = [[UIView alloc] initWithFrame:self.view.frame];
"some code here setting up the subviews"
[buttonLeft addTarget:self action:@selector(startGame) forControlEvents:UIControlEventTouchUpInside];
[_firstScreen addSubview:mainMenuBackground];
[_firstScreen addSubview:buttonLeft];
[_firstScreen addSubview:buttonMid];
[_firstScreen addSubview:buttonRight];
[_mainContainer addSubview:_firstScreen];
Essentially if I add everything directly to _mainContainer, the buttons work, if I add it to _firstScreen, then add _firstScreen they don't work. 本质上,如果我将所有内容直接添加到_mainContainer,则按钮会起作用,如果我将其添加到_firstScreen,然后添加_firstScreen则它们将不起作用。
User interaction is enabled on _firstScreen. 在_firstScreen上启用了用户交互。 I do something similar later in my app and it works fine. 稍后我会在我的应用中执行类似的操作,并且效果很好。 Also, not sure if this has anything to do with it, but despite my screen being displayed in landscape, and all options in the plist being set to landscape only, when I run a transition, like flipFromBottom (or whatever its called), my app thinks the "bottom" is with the screen being in portrait until I move to another group of subviews in my app. 另外,不确定是否与它有任何关系,但是尽管我的屏幕显示为横向,并且plist中的所有选项都设置为仅横向,但是当我运行过渡时,例如flipFromBottom(或它的任何名称),我的应用程序认为屏幕底部是“底部”,直到我移到应用程序中的另一组子视图为止。 (So basically the title screen is acting screwy). (因此,标题屏幕基本上是固定的)。
I looked everywhere for a solution, hopefully I am not missing something basic. 我到处都在寻找解决方案,希望我不会缺少一些基本知识。
Hey what is mainMenuBackground?, if its a image , their is no need to make it as a subView, instead, the correct way is to set it as a background image. 嘿,mainMenuBackground是什么?如果它是image,则不需要将其设置为subView,而是将其设置为背景图像是正确的方法。 I hope this will solve your problem 我希望这能解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.