【问题标题】:How to make a draw over an UIImageView (iOS4)如何在 UIImageView (iOS4) 上进行绘制
【发布时间】:2011-07-20 14:33:31
【问题描述】:

我将 XCode 4.0.2 用于 iOS4 项目。

我有一个MainView.xib 和一个MainViewController

我在MainView.xib 中插入了一个UIImageView 和一张图片。

在 Identity Inspector 中,我给 UIImageView 一个自定义类图。

我创建了两个新文件Diagram.hDiagram.c。在Diagram.m我已经插入了

 - (void)drawRect:(CGRect)rect {
     UIGraphicsBeginImageContext(self.bounds.size); 
     CGContextRef context = UIGraphicsGetCurrentContext();

     CGContextSetLineWidth(context, 2.0);
     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
     CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
     CGColorRef color = CGColorCreate(colorspace, components);
     CGContextSetStrokeColorWithColor(context, color);

     CGContextMoveToPoint(context, 0, 0);
     CGContextAddLineToPoint(context, 200, 200);

     CGContextStrokePath(context);
     CGColorSpaceRelease(colorspace);
     CGColorRelease(color);
 }

当我运行应用程序时,我可以看到图像(在UIImageView,但绘图没有完成。也许没有调用。我该怎么办?

谢谢。

【问题讨论】:

  • 如果你删除图像,你能看到在你的drawRect方法中发生的绘图吗?即UIImageView 是否在您的自定义绘图之上绘制图像。
  • 不,图片下方没有绘图。

标签: iphone ios4 uiimage drawing


【解决方案1】:

答案在 Apple 官方文档中

特别注意事项

UIImageView 类经过优化,可以将其图像绘制到显示器上。 UIImageView 不会在子类上调用 drawRect:。如果您的子类需要自定义绘图代码,建议您使用 UIView 作为基类。

您可以在this question查看更多详情

【讨论】:

    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多