gpt4 book ai didi

iOS - UIView 总是在前面,没有 BringSubviewToFront

转载 作者:行者123 更新时间:2023-12-01 17:40:11 29 4
gpt4 key购买 nike

我可以要一些吗 UIView 哪个将始终出现在 iOS 的顶部?

有很多addSubview在我的项目中,但我需要一个始终出现的小 View 。那么除了

[self.view bringSubViewToFront:myView];

谢谢

最佳答案

另一种选择(特别是如果您想重叠多个屏幕,例如带有 Logo ) - 单独的 UIWindow。使用windowLevel设置新窗口的级别。

UILabel *devLabel = [UILabel new];
devLabel.text = @" DEV ";
devLabel.font = [UIFont systemFontOfSize:10];
devLabel.textColor = [UIColor grayColor];
[devLabel sizeToFit];

CGSize screenSize = [[UIScreen mainScreen] bounds].size;
static UIWindow *notificationWindow;
notificationWindow = [[UIWindow alloc] initWithFrame:
CGRectMake(screenSize.width - devLabel.width, screenSize.height - devLabel.height,
devLabel.width, devLabel.height)];
notificationWindow.backgroundColor = [UIColor clearColor];
notificationWindow.userInteractionEnabled = NO;
notificationWindow.windowLevel = UIWindowLevelStatusBar;
notificationWindow.rootViewController = [UIViewController new];
[notificationWindow.rootViewController.view addSubview:devLabel];
notificationWindow.hidden = NO;

关于iOS - UIView 总是在前面,没有 BringSubviewToFront,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22728669/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com