【发布时间】:2016-02-13 00:18:18
【问题描述】:
我有一个 UIViewController,它在情节提要中设置了 UI 元素,并且一切正常。现在我在单独的 xib、.h 和 .m 文件中创建了一个新的 UIView,我将其称为“覆盖”;然后我展示应该覆盖下面所有内容的覆盖层,以便只能看到覆盖层:
// in controller.m
OverlayView *overlayView = [[OverlayView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
overlayView.layer.zPosition = 1000;
[self.view addSubview:overlayView];
覆盖出现在一个奇怪的位置(它的顶部距离导航栏的底部大约 50 像素)。更重要的是,除了叠加层的背景之外,看不到叠加层中的任何元素。它只是一块空白的红色画布。我仔细检查了元素的 alpha 值是否为 1,它们被设置为不隐藏,并且它们也在覆盖的 initWithFrame 中明确设置:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor redColor]; // red canvas shows up
self.title.textColor = [UIColor blackColor]; // title can't be seen; why not?
self.body.textColor = [UIColor blackColor]; // body can't be seen; why not?
}
return self;
}
我不直接将叠加层放在控制器的xib中然后简单地更改它的hidden属性的原因是这个叠加层将被多个控制器使用,我想重新使用它,因此把它作为一个单独的视图。
我做错了什么?
【问题讨论】:
标签: ios objective-c uiview uiviewcontroller viewdidload