【问题标题】:How to draw a rectangle on imageview instead of a view in ipad如何在 imageview 上绘制矩形而不是 ipad 中的视图
【发布时间】:2012-07-03 19:12:42
【问题描述】:

嗨,在我的项目中,我有一个图像视图,我想用手指在图像视图上绘制一个矩形或圆形。现在我已经使用 CGContext 类方法做了,但是矩形和圆形是在一个 UIView 对象上创建的绘制矩形方法的帮助。该创建的视图正在像圆形或矩形一样添加到 imageview 上,但我希望直接在 imageview 上绘制它是可能的,请在这个问题上帮助我。

【问题讨论】:

  • UIImageView 是 UIView 的子类。您是否尝试过覆盖 UIImageView 的 drawRect?

标签: iphone cgcontext


【解决方案1】:

UIImageView 是 UIView 的子类,但不能为 UIImageView 覆盖 drawRect:

尝试添加一个子层并使用委托和drawLayer:inContext:方法在该子层中绘制

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/ProvidingCALayerContent.html

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多