【发布时间】:2013-10-30 07:39:00
【问题描述】:
我在 Interface Builder 中创建了一个 UIView,我们称之为 viewFromIB,并在我的 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 添加为modalViewType 的子视图,并使用bringSubviewToFront: 方法将viewFromIB 置于前面。但是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 并在 self.view 上取消隐藏 viewFromIB 和 bringSubviewToFront: 它工作正常。只有在尝试添加modalViewType 的子视图时才会出现问题。我的 subView 的框架似乎完全合乎逻辑。
【问题讨论】:
-
试试,self.view bringSubviewToFront:viewFromIB];
-
@karthika 我已经尝试过了。它不起作用,因为
[modalViewType addSubview:viewFromIB];已将 viewFromIB 的超级视图更改为 modalViewType
标签: ios objective-c uiview