gpt4 book ai didi

ios - 其他 View 之上的 UIView 不起作用

转载 作者:行者123 更新时间:2023-11-28 21:56:11 24 4
gpt4 key购买 nike

我不明白为什么我的代码不会将这个自定义 View 放在主视图之上。任何建议都会很棒。

这是我的代码:

.h

@property (strong, nonatomic) IBOutlet UIView *saved;

.m

self.saved = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
self.saved.backgroundColor = [UIColor colorWithRed:0.0/255 green:102.0/255 blue:153.0/255 alpha:1];
[self.view bringSubviewToFront:self.saved];

最佳答案

您需要在调用 bringSubviewToFront 之前添加为 subview [self.view addSubview:self.saved];

请注意:您已将您的属性声明为IBOutlet,该宏用于表示可以在Interface Builder 中引用的变量。如果您计划从 Interface Builder 创建和包含 subview ,则无需通过代码初始化和添加为 subview 。

关于ios - 其他 View 之上的 UIView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26458502/

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