wacky image stretching on rotation (repost)

  • I have a UIImageView in a custom TableViewCell that I want to rotate to
    arbitrary angles.  When I apply a rotation transformation like so:

    CGAffineTransform rotation = CGAffineTransformMakeRotation(15 * (M_PI /
    180));

    [self.thumbImageView setTransform:rotation];

    The image is not only rotated but stretched significantly in the horizontal
    direction.  It's not a content-resizing problem, because the originally
    square UIImageView is now clearly not square.  Screen shot here:
    http://farm8.staticflickr.com/7132/7513267936_bbff9019b5_b.jpg

    Anybody know what's going on with this?

    Thanks!
  • Check self.thumbImageView.contentMode - it's probably the default
    UIViewContentModeScaleToFill (should be UIViewContentModeCenter). Also
    ensure that the UIImage that you provide really has square dimensions. I had
    the exact same issue when rotating the UIImageView of a UIButton...

    > I have a UIImageView in a custom TableViewCell that I want to rotate
    > to arbitrary angles.  When I apply a rotation transformation like so:
    >
    > CGAffineTransform rotation = CGAffineTransformMakeRotation(15 * (M_PI /
    180));
    >
    > [self.thumbImageView setTransform:rotation];
    >
    > The image is not only rotated but stretched significantly in the
    horizontal
    > direction.  It's not a content-resizing problem, because the originally
    > square UIImageView is now clearly not square.  Screen shot here:
    > http://farm8.staticflickr.com/7132/7513267936_bbff9019b5_b.jpg
    >
    > Anybody know what's going on with this?
  • Thanks for the reply, Julius.  I had the mode set to
    UIViewContentModeScaleToFill.

    Setting it to UIViewContentModeCenter does allow the image to rotate
    undistorted, but the frame is still ridiculously distorted.  And look at
    the massive difference in distortion for a tiny difference in angle between
    the top two:
    http://farm8.staticflickr.com/7246/7513766824_c3c47de76b.jpg

    This seems wrong.
  • I would suspect that the UIImageView's autoresizingMask might be the culprit
    - if it isn't UIViewAutoresizingNone, then the frame may be resizing itself
    when rotated. Sometimes it is less trouble to create your own
    UITableViewCell subclass and have full control over your subviews instead of
    trying to twiddle a standard UITableViewCell to do what you want... :)

    > Setting it to UIViewContentModeCenter does allow
    > the image to rotate undistorted, but the frame is
    > still ridiculously distorted.  And look at the massive
    > difference in distortion for a tiny difference in angle
    > between the top two:
    > http://farm8.staticflickr.com/7246/7513766824_c3c47de76b.jpg
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today