addSubview 在 iOS 3.1.3 上不显示视图

发布于 2024-09-09 12:14:00 字数 716 浏览 7 评论 0原文

我有一个滚动视图,其中有一个 UIView ,其中包含内容。我添加一个 UIImageView 作为 UIScrollView 的子部分(因此它应该位于内容容器的顶部),这适用于 iPhone 3.2+,但在运行的 iPhone 上3.1.3 图像没有显示在容器上方。我的代码是这样的:

    // add the content container
    UIView *contentContainer = [[UIView alloc] init];
    [scrollView addSubview:contentContainer];

    // add content, etc

    // this works in 3.2+
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [scrollView addSubview:imageView];
    // tried adding this for 3.1, but still didn't work
    [scrollView bringSubviewToFront:imageView];
    [imageView setFrame:CGRectMake(point.x, point.y, image.size.width, image.size.height)];

我还缺少其他东西吗?谢谢!

I have a scroll view which has one UIView inside which contains the content. I am adding a UIImageView as a sub of the UIScrollView (so it should be on top of the content container) and this works on iPhone 3.2+, but on an iPhone running 3.1.3 the image does not show up above the container. My code is something like this:

    // add the content container
    UIView *contentContainer = [[UIView alloc] init];
    [scrollView addSubview:contentContainer];

    // add content, etc

    // this works in 3.2+
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [scrollView addSubview:imageView];
    // tried adding this for 3.1, but still didn't work
    [scrollView bringSubviewToFront:imageView];
    [imageView setFrame:CGRectMake(point.x, point.y, image.size.width, image.size.height)];

Is there something else that I'm missing? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心 2024-09-16 12:14:03

发现问题:当我指定图像名称时,我没有指定图像扩展名:

UIImage *image = [UIImage imageNamed:@"myImage"];

如果我将其更改为以下内容,它会起作用:

UIImage *image = [UIImage imageNamed:@"myImage.png"];

iOS是否知道在存在扩展名时仍然查找“@2x”版本(如果可用)偶然?

Found the issue: when I specified the image name, I was not specifying the image extension:

UIImage *image = [UIImage imageNamed:@"myImage"];

If I change this to the following, it works:

UIImage *image = [UIImage imageNamed:@"myImage.png"];

Does iOS know to still look for the "@2x" version if available when the extension is present by chance?

温柔少女心 2024-09-16 12:14:02

您是否实际上还设置了 UIScrollViewcontentSize 属性?

Are you also actually setting the contentSize property of the UIScrollView ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文