[英]How to draw an UIImageView in -drawRect:?
I'm trying since 5 hours now: 我从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);
}
The problem: While the image draws correctly, the coordinates specified by the UIImageView frame are completely useless. 问题:当图像正确绘制时,UIImageView框架指定的坐标完全没有用。 The image appears placed completely wrong on screen.
图像看起来完全错误地放在屏幕上。
I guess I must also flip the CGRect of the UIImageView? 我想我还必须翻转UIImageView的CGRect吗? But how?
但是如何?
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html
The UIImageView class is optimized to draw its images to the display. UIImageView类经过优化,可以将其图像绘制到显示器上。 UIImageView will not call drawRect: a subclass.
UIImageView不会调用drawRect:一个子类。 If your subclass needs custom drawing code, it is recommended you use UIView as the base class.
如果您的子类需要自定义绘图代码,则建议您使用UIView作为基类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.