[英]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嗎? 但是如何?
UIImageView類經過優化,可以將其圖像繪制到顯示器上。 UIImageView不會調用drawRect:一個子類。 如果您的子類需要自定義繪圖代碼,則建議您使用UIView作為基類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.