0

我有一个 UIView 子类,我在 drawRect 方法中绘图。

如何在 drawRect 目标层之上添加覆盖图像?

我在方法中添加以下内容initWithFrame

    //add the image overlay
    UIImageView *overlageImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downloaderFront.png"]];
    overlageImage.center = self.center;
    [self.layer addSublayer:overlageImage.layer];
    //replacing the above line with below line does not fix either
    [self addSubview:overlageImage];

此图像在 drawRect 绘图的顶部不可见。

4

1 回答 1

0

带有图层的东西肯定是错误的。只需这样做:

UIImageView *overlageImage = 
    [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downloaderFront.png"]];
[self addSubview:overlageImage];

您可以使用框架overlageImage来获得所需的位置。

至于你的实际问题:放一个断点。我怀疑您会发现您的代码甚至从未运行(因为您的视图initWithFrame从未被调用)。这只是一个猜测——你没有说这个 UIView 子类实例是如何进入界面的——但这是一个很常见的错误,人们应该总是首先怀疑明显的错误!

于 2013-05-12T17:27:26.703 回答