gpt4 book ai didi

objective-c - 关于 View 层次结构,需要澄清

转载 作者:行者123 更新时间:2023-11-28 23:11:18 25 4
gpt4 key购买 nike

在此代码示例中,我试图生成以下 View 层次结构

Window -> background image -> scroll view -> text view

不过我看到的是

Window -> background image

请问我错过了什么?

-(void) viewWillAppear:(BOOL)animated {

UIScrollView *scrollWindow = [[UIScrollView alloc]
initWithFrame:CGRectMake(30, 30, 440, 212)];

UITextView *scrollableText = [[UITextView alloc] init];

[scrollableText setEditable:NO];
[scrollableText setText:@"Why, hello there"];

[scrollWindow addSubview:scrollableText];

UIImage *backgroundImage = [[UIImage alloc] initWithCGImage:
[UIImage imageNamed:@"about_bg.png"].CGImage];
UIImageView *backgroundView = [[UIImageView alloc]
initWithImage:backgroundImage];

[backgroundView addSubview:scrollWindow];

[[self view] addSubview:backgroundView];

}

最佳答案

Andrew 关于不让 ScrollView 成为背景 UIImageView View 的 subview 是正确的。但是 ScrollView 不可见的。只有它的内容 (scrollableText) 会显示。而且您还没有设置 scrollableText 的框架,所以它实际上也是不可见的。像这样初始化:

[scrollableText setEditable:NO];
[scrollableText setText:@"Why, hello there"];
[scrollableText setFrame:CGRectMake(0, 0, 100, 100)];

你应该会看到它。

关于objective-c - 关于 View 层次结构,需要澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8205889/

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