I have the following code:
UIImageView * imgView = [[UIImageView alloc] initWithImage:image];
NSLog(@"IMAGE SIZE WIDTH IS %f AND HEIGHT IS %f", imgView.frame.size.width, imgView.frame.size.height);
[imgView setUserInteractionEnabled:YES];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
CGRect frame = imgView.frame;
frame.size.width = SCREEN_WIDTH_PORTRAIT;
[imgView setFrame: frame];
however, the height of this view did not change accordingly, what is wrong?
You’re telling the view’s content to scale, not the view itself. You will have to set both the width and the height to do that.
If you’re just trying to scale with orientation changes, though, you could use the UIViewAutoresizingMask and set it like this:
That will make it stretch when switching orientations automatically.
Edit:
Here’s how you would change the height and maintain the ratio, and animate to the new frame: