UIImageView size becomes equal to the size of image it holds after autoresizing

Posted by abura on Stack Overflow See other posts from Stack Overflow or by abura
Published on 2010-06-01T09:29:53Z Indexed on 2010/06/01 9:33 UTC
Read the original article Hit count: 602

Hello,

I faced a strange problem. My task is to provide scaling an image to fill the UIImageView frame. The UIImageView is a subview of another view.

The code is following:

CGRect frame=CGRectMake(0,0,viewSize.width,viewSize.height); UIView* backView=[[UIView alloc] initWithFrame:frame]; backView.autoresizesSubviews=YES; backView.autoresizingMask=UIViewAutoresizingFlexibleWidth; UIImageView* imgView=[[UIImageView alloc]initWithFrame:viewFrame]; imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; imgView.contentMode=UIViewContentModeScaleToFill; [subcellBackView addSubview:imgView]; [imgView release];

When the image arrives, it is assigned the the imgView:

imgView.image=img;

The image is scaled according to the imgView's size. Everything is all right until the iPhone (simulator) rotation. After first autoresizing the imgView size becomes equal to the image size (which is much greater) and overlaps its superview frame. The superview frame reacts properly to the orientation change.

Could you please help?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiimageview