proper fill an image larger than screen
<p>what I wanted to achieve here is simply fit the image width to the screen on both orientations and use UIScrollView to just allow scroll vertically to see the whole image.</p>

<p>both viewController and view are created pragmatically.</p>

<p>the image loaded is larger than screen on both width and height.</p>

<p>here is the related code in my viewController:</p>

<pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;    
}

- (void)loadView {
    UIScreen *screen = [UIScreen mainScreen];
    CGRect rect = [screen applicationFrame];
    self.view = [[UIView alloc] initWithFrame:rect];
    self.view.contentMode = UIViewContentModeScaleAspectFill;
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    UIImage *img=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]];
    UIImageView *imgView =[[UIImageView alloc] initWithImage:img];
    [img release];

    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [self.view addSubview:imgView];
    [imgView release];
}
</code></pre>

<p>tried all combinations for both contentMode above, did not give me correct result.</p>

<p>the most close I am getting now: I manually resize imgView in loadView, portrait mode would display correctly since app always starts with portrait mode, but in landscape mode, the width fits correctly, but image is centered vertically rather than top aligned.</p>

<p>if I add the imgView to a scrollView, in landscape mode it looks like contentSize is not set to full image size. but when I scroll bounce I can see the image is there in full size.</p>

<p>question:</p>

<ol>
<li><p>why I need to resize it manually? </p></li>
<li><p>in landscape mode how and where I can 'move' the imgView, so imgView.frame.origin is (0,0) and works correctly with a scroll view?</p></li>
</ol>

<p>Thanks!</p>

<p>UPDATE:
I added:
    imgView.clipsToBounds = YES;</p>

<p>and find out in landscape mode the image bounds is smaller than screen in height.</p>

<p>so the question becomes how to have the image view keeps original ratio (thus shows the full image always) when rotated to landscape? do I need to manually resize it after rotation again?</p>
