简体   繁体   中英

How to draw an UIImageView in -drawRect:?

I'm trying since 5 hours now:

- (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. The image appears placed completely wrong on screen.

I guess I must also flip the CGRect of the UIImageView? But how?

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 will not call drawRect: a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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