我正在使用以下代码创建一个视图并将其放在顶部:
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
CGRect viewRect = mainWindow.frame;
topView = [[UIView alloc] initWithFrame:viewRect];
[topView setBackgroundColor:[UIColor colorWithWhite:0.2 alpha:0.4]];
[mainWindow addSubview:topView];
它工作得很好,但我的问题是如果我在视图中写任何东西(比如使用标签)并且我的设备处于横向位置,文本处于垂直位置。我附上了一张图片,以使其更清楚。有什么办法可以解决吗?
编辑:如果我使用 UIApplication.sharedApplication.keyWindow.rootViewController 而不是 mainWindow,我会得到这个: