gpt4 book ai didi

ios - UIView BOOL 的奇怪行为

转载 作者:行者123 更新时间:2023-12-01 18:43:55 25 4
gpt4 key购买 nike

我已经定制了UIView我在 UIViewController 上代表. View 显示在屏幕上,但我在该 UIView 实例上设置为 YES 的 BOOL 无法识别。

代码:

UIView 实现:

- (id)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];
if (self) {
[self createInterface];
}
return self;
}

-(void)createInterface
{
if (self.isSplash == YES) {
self.backgroundColor = [UIColor clearColor];
}
else {
self.backgroundColor = DARK_BLUE;
[self setupTimer];

}
....

View Controller :
self.sponsorView = [[SponsorMechanismView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.logo.frame)+10, SCREEN_WIDTH, 100)];
self.sponsorView.isSplash = YES;

[self.view addSubview:self.sponsorView];

因此,我将 BOOL 设置为 YES,但在此 UIView 中它始终为 NO。

最佳答案

正如 Fabio 所说,createInterface 已经执行。
您可以做的是创建自己的 init 函数。像这样的东西:

- (id)initWithFrame:(CGRect)frame isSplash(BOOL)isSplash
{
self = [super initWithFrame:frame];
self.isSplash = isSplash;
if (self) {
[self createInterface];
}
return self;
}

函数的调用将如下所示:
self.sponsorView = [[SponsorMechanismView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.logo.frame)+10, SCREEN_WIDTH, 100) isSplash:YES];

关于ios - UIView BOOL 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38392051/

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