我viewFromIB
在 Interface Builder 中创建了一个 UIView,我们称之为它,并在我的 ViewController 加载时隐藏了它。我正在创建另一个 UIView ,让我们modalViewType
通过代码调用它并将其添加为子视图self.navigationController.view
:
UIView *modalViewType = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
modalViewType.opaque = NO;
modalViewType.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
[self.navigationController.view addSubview:modalViewType];
现在我正在取消隐藏viewFromIB
,添加viewFromIB
为 subViewmodalViewType
并viewFromIB
使用bringSubviewToFront:
方法将其置于前面。但viewFromIB
不是变得可见,虽然我能看到modalViewType
。这是代码:
viewFromIB.hidden = NO;
viewFromIB.layer.masksToBounds = YES;
viewFromIB.center = CGPointMake(modalViewType.frame.size.width/2, modalViewType.frame.size.height/2);
[modalViewType addSubview:viewFromIB];
[modalViewType bringSubviewToFront:viewFromIB];
仅供参考,这曾经在 iOS6 中运行良好,但现在在 iOS7 中大发雷霆。如果需要任何其他信息,请告诉我。非常感谢。
更新:如果我不使用modalViewType
UIView 而只是取消隐藏viewFromIB
它就bringSubviewToFront:
可以self.view
正常工作。仅当我尝试添加modalViewType
. 我的 subView 的框架似乎完全合乎逻辑。