【问题标题】:How to draw an UIImageView in -drawRect:?如何在 -drawRect: 中绘制 UIImageView?
【发布时间】:2010-04-23 08:50:13
【问题描述】:

我从现在开始尝试 5 个小时:

- (void)drawRect:(CGRect)rect {
    // flip the wrong coordinate system
    CGContextTranslateCTM(context, 0.0f, rect.size.height); //shift the origin up
    CGContextScaleCTM(context, 1.0f, -1.0f); //flip the y-axis

    CGContextDrawImage(context, myImgView.frame, myImageView.image.CGImage);
}

问题:虽然图像绘制正确,但 UIImageView 框架指定的坐标完全没用。图像在屏幕上的位置完全错误。

我想我还必须翻转 UIImageView 的 CGRect 吗?但是怎么做呢?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多