82931

How to draw an UIImageView in -drawRect:?

Question:

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?

Answer1:

<a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html" rel="nofollow">http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html</a>

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.

Recommend

  • MapKit Adding Raster Map via MKOverlay Weird Rendering Issue
  • Trying to run a function on an array in a, for loop, using jsrender
  • JFrame appears blank when components are loading images outside the paintComponent(); method
  • Cocoa MVC: where is application work logic intended to be placed?
  • Drawing a rectangle on UIImageView using Core Graphics
  • Issue to parse json
  • Plotting series histogram in Pandas
  • Copying the drawn contents of one UIView to another
  • How to print this pyramid pattern?
  • how do i display the coordinates of a random triangle in actionscript 2.0?
  • XNA BlendState with SpriteBatch
  • Java last added button allows agent.move, rest dont
  • Changing the axis scale in numpy plot
  • Drawing multiple triangles in OpenGL
  • draw graphics outside of paint method
  • Create Elevation profile from polyline coordinate array
  • How to get subviews frames early in initialization process
  • Toggle setLineDash()
  • How do js animations work?
  • multiple colors on beanplot in R
  • Is PascalScript compatible with Delphi XE5 to create Android/iOS/Windows applications?
  • How to increase the python speed over loops?
  • How to get a Windows Forms panel as a bitmap with C#?
  • How to make a local git repository that mirrors an upstream repository?
  • Keep same scale in different graphs ggplot2
  • Accessing Windows Azure Queues from client side javascript/jquery
  • JFreechart X and Y axis scaling
  • Why do GeoJSON features appear like a negative photo of the features themselves?
  • JSON - slashes not escaping
  • Google Maps api v3 get start and end coordinates of a street
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • Breaking out column by groups in Pandas
  • wxPython: displaying multiple widgets in same frame
  • R - Combining Columns to String Based on Logical Match
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • embed rChart in Markdown
  • costura.fody for a dll that references another dll
  • Unable to use reactive element in my shiny app
  • git trying to push non-existent file … after clearing cache