![](/img/trans.png)
[英]In an iOS app, even when no main custom UIView is added, I can still add other view objects as subview?
[英]UIButton not receiving touches when added to subview, but does when added to main view
基本上,我有一个主屏幕,上面带有背景图像和屏幕底部的三个菜单选项。 当我将这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];
本质上,如果我将所有内容直接添加到_mainContainer,则按钮会起作用,如果我将其添加到_firstScreen,然后添加_firstScreen则它们将不起作用。
在_firstScreen上启用了用户交互。 稍后我会在我的应用中执行类似的操作,并且效果很好。 另外,不确定是否与它有任何关系,但是尽管我的屏幕显示为横向,并且plist中的所有选项都设置为仅横向,但是当我运行过渡时,例如flipFromBottom(或它的任何名称),我的应用程序认为屏幕底部是“底部”,直到我移到应用程序中的另一组子视图为止。 (因此,标题屏幕基本上是固定的)。
我到处都在寻找解决方案,希望我不会缺少一些基本知识。
嘿,mainMenuBackground是什么?如果它是image,则不需要将其设置为subView,而是将其设置为背景图像是正确的方法。 我希望这能解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.