【问题标题】:Layers of Images using UIImageView使用 UIImageView 的图像层
【发布时间】:2010-05-21 11:54:26
【问题描述】:

我只是想确认一下,我们是否可以使用 UImageView 添加图像层,一个作为背景,另一个在它上面。我的意思是我想使用两张图片,一张必须在背景中,另一张在上面。 (这两个图像的大小都是 320 x 480)。

通过属性检查器我们不能做到这一点。有什么我们可以通过代码做到的。 也许使用子视图或其他东西。

【问题讨论】:

    标签: iphone objective-c uiimageview uiimage


    【解决方案1】:

    每个图像都需要一个 UIImageView,但只要顶视图不是不透明的,它们就会分层显示。如果您想将它们视为单个实体,可以将两个图像视图放入第三个 UIView。

    编辑:

    imageBackground = [[UIImageView alloc] initWithImage:[UIImageNamed:@"background.png"]];
    imageForeground = [[UIImageView alloc] initWithImage:[UIImageNamed:@"foreground.png"]];
    imageLayered = [[UIView alloc] initWithFrame:[imageBackground frame];
    
    [imageLayered addSubview:imageBackground];
    [imageLayered addSubview:imageForeground];
    
    // release all views at some point.
    

    imageLayered 现在是一个带有背景和前景图像的 UIView。

    【讨论】:

    • 谢谢@drawnonward 。我部分明白了你的观点。每张图片我都需要一个 UImageView ,我会做的。那么我怎样才能将它们分层放置,以便它们可以在背景中被视为一个,而另一个在它之上。
    • @drawnonward 我只是想确认一下。我应该使用 self.view 而不是 imageLayered 吗?或者我必须添加另一个视图,比如“imageLayered”并连接它。之后会显示 2 层图像
    • 是的,您可以使用 self.view 代替 imageLayered。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多