4

I need to rotate by a given angle a UIImageView created by Interface builder when the view is loaded.

- (void)viewDidLoad
{
   [super viewDidLoad];
    image.transform = CGAffineTransformRotate(image.transform, REF_INIT_OFFSET*M_PI/180); 
}

This rotates the image but the latter is totally distorted and stretched. If REF_INIT_OFFSET is a multiple of 90 it works fine !

Here is how the picture should look like (note the needle pointing to the "0")

enter image description here

and here is how it actually looks:

it looks like the image is stretched into a wrong direction.

Do you have in idea what's wrong ?

thanks,

1 Answer 1

7

Not sure that it help you, but I had the same problem after [UIImage setFrame:] if UIImage was transformed , the decision was using setBounds instead of setFrame

Solving the problem on the discussion in the comments:

Method setFrame is called after viewDidLoad in shouldAutorotateToInterfaceOrientation implicitly if autoresizesSubviews property YES

- (void)viewDidLoad {
[super viewDidLoad];
self.view.autoresizesSubviews=NO;
image.transform = CGAffineTransformRotate(image.transform, 50*M_PI/180);
}
6
  • Just test your situation, it seems that the method setFrame is called after viewDidLoad in shouldAutorotateToInterfaceOrientation implicitly if autoresizesSubviews property YES. But I can't get this error again after first change autoresizesSubviews value
    – aknew
    Jul 6, 2011 at 13:59
  • Actually I have the same problem after I rotate the UI when the device orientation is changed .. What exactly shall I "test" ?
    – Jan
    Jul 6, 2011 at 14:24
  • This help to me:- (void)viewDidLoad { [super viewDidLoad]; self.view.autoresizesSubviews=NO; image.transform = CGAffineTransformRotate(image.transform, 50*M_PI/180); But is your image subview of self.view or of one its subview? }
    – aknew
    Jul 6, 2011 at 14:33
  • 2
    self.view.autoresizesSubviews = NO; that seems to be the solution ! thanks !
    – Jan
    Jul 6, 2011 at 16:00
  • sorry, I'm a newbie in Stack Overflow .. how can I accept your last comment as the solution ?
    – Jan
    Jul 6, 2011 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.