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


  窗口->背景图片->滚动视图->文本视图


我所看到的只是


  窗口->背景图片


我想念什么?

-(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)不使滚动视图成为背景UIImageView视图的子视图是正确的。但是滚动视图是不可见的。仅显示其内容(scrollableText)。而且您还没有设置scrollableText的框架,因此它实际上也是不可见的。像这样初始化:

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


而且您应该看到它。

08-05 23:53