views:

569

answers:

1

In a UIScrollView I have a UIImageView with the contentMode set to Aspect Fill. When I rotate the simulator to landscape mode the UIImageView shows the center of the image and I cannot scroll upwards to see the whole picture.

How do I fix this so that when I rotate the iPhone I instead see the top of the image (but still scaled with Aspect Fill).

A: 

Needed to set the size of the frame:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    CGFloat ratio = imageView.frame.size.width/imageView.image.size.width;
    CGRect rect = CGRectMake(0, 0, imageView.frame.size.width , ratio*imageView.image.size.height);
    [scrollView setContentSize:rect.size];
    [imageView setFrame:CGRectMake(0.0f, 0.0f, rect.size.width, rect.size.height)];
}
Daniel W