繁体   English   中英

如何在-drawRect:中绘制UIImageView?

[英]How to draw an UIImageView in -drawRect:?

我从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吗? 但是如何?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM