UIImageView size becomes equal to the size of image it holds after autoresizing
- by abura
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?