Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:17:06+00:00 2026-06-15T01:17:06+00:00

I have the following code in ViewDidLoad and it squashes my UIImage/ UIImageView. I

  • 0

I have the following code in ViewDidLoad and it squashes my UIImage/ UIImageView. I want the image to fill the UIScrollView.

[super viewDidLoad];

_imageHolder = [[UIImageView alloc]initWithFrame:self.view.frame];
_scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame]; 

[_scrollView setBackgroundColor:[UIColor purpleColor]];

// Tell the scroll view the size of the contents
self.scrollView.contentSize = self.view.frame.size;

self.scrollView.delegate = self;
self.scrollView.scrollEnabled = YES;

FfThumbnailData* thumbData = [self.arrayOfImages objectAtIndex:self.thisImageIndex];
UIImage* fullSizedImage = [[UIImage alloc]initWithContentsOfFile:thumbData.path];
[self.imageHolder setImage:fullSizedImage];
float x = fullSizedImage.size.width;
float y = fullSizedImage.size.height;
CGRect rect = CGRectMake(0, 0, x, y);
NSLog(@"Size of image: %@", NSStringFromCGRect(rect));
//
//[self.imageHolder setImage:[UIImage imageNamed:@"P1020486.png"]];

[self.scrollView addSubview:_imageHolder];
[self.view addSubview:self.scrollView];

_imageHolder.contentMode = UIViewContentModeScaleAspectFit;

I set the backgound of the UIScrollView to purple for clarity:

Squashed by UIScrollViewhttp://i1219.photobucket.com/albums/dd427/Dave_Chambers/IMG_0315.png

I should add that after I zoom in and then zoom out, the image IS correctly placed in the scrollview and not squashed.

Strangely, the commented line [self.imageHolder setImage:[UIImage imageNamed:@"P1020486.png"]]; correctly displays the dummy image P1020486.png.

Also, when I download my app data, the image looks right and is indeed the correct size of an iPad image – {1936, 2592} – the size reported by my NSLog line NSLog(@"Size of image: %@", NSStringFromCGRect(rect));

Further, before I needed a UIScrollView (for zooming the photo in the full size View Controller) I access the same image and display it via an animation from one View Controller to another with the following code and it displays correctly. Crucially thought, this second section of code lacks a UIScollview.

-(void)animateTransition:(int)buttonInPositon {
@try {

FfThumbnailData* thumbData = [self.images objectAtIndex:buttonInPositon];
UIImage* fullSizedImage = [[UIImage alloc]initWithContentsOfFile:thumbData.path];
fullSize = [[FullSizeViewController alloc]init];
fullSize.imageHolderGhost.contentMode = UIViewContentModeScaleAspectFit;
fullSize.arrayOfImages = self.images;
fullSize.imageToPresent = fullSizedImage;
fullSize.numberOfImages = self.images.count;
fullSize.thisImageIndex = buttonInPositon;
[fullSize.imageHolderGhost setImage:fullSizedImage];

float screenWidth = self.view.bounds.size.width;
float screenHeight = self.view.bounds.size.height;

NSLog(@"ButtonFrame: %@", NSStringFromCGRect(buttonFrame));
[fullSize.view setFrame:CGRectMake(buttonFrame.origin.x, buttonFrame.origin.y, buttonFrame.size.width, buttonFrame.size.height-44)];
NSLog(@"ButtonFrame: %@", NSStringFromCGRect(fullSize.view.frame));

[self.view addSubview:fullSize.view];

fullSize.view.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.9 delay:0 options:UIViewAnimationCurveEaseIn animations:^{

    [fullSize.view setFrame:CGRectMake(0, 0, screenWidth, screenHeight)];


} completion:^(BOOL finished){
    [[self navigationController] pushViewController:fullSize animated:NO];
    self.navigationController.navigationBarHidden = YES;
}];
}
@catch (NSException *exception) {
    NSLog(@"%@", exception);
}
}

For completeness, the code with the UIScrollView has the following method in one VC:

-(void)presentWithScrollview:(int)buttonInPositon {

FfThumbnailData* thumbData = [self.images objectAtIndex:buttonInPositon];
UIImage* fullSizedImage = [[UIImage alloc]initWithContentsOfFile:thumbData.path];

fullSize = [[FullSizeViewController alloc]init];

fullSize.arrayOfImages = self.images;
fullSize.imageToPresent = fullSizedImage;
fullSize.numberOfImages = self.images.count;
fullSize.thisImageIndex = buttonInPositon;

[[self navigationController] pushViewController:fullSize animated:NO];
    self.navigationController.navigationBarHidden = YES;
}

and in the destination VC the following methods may be relevant to my problem (ViewDidLoad pasted at the top of this question):

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Set up the minimum & maximum zoom scales
    CGRect scrollViewFrame = self.scrollView.frame;
    CGFloat scaleWidth = scrollViewFrame.size.width / self.scrollView.contentSize.width;
    CGFloat scaleHeight = scrollViewFrame.size.height / self.scrollView.contentSize.height;
    CGFloat minScale = MIN(scaleWidth, scaleHeight);
    //
self.scrollView.minimumZoomScale = minScale;
//Can set this bigger if needs be - match iPhoto
self.scrollView.maximumZoomScale = 2.0f;

[self centerScrollViewContents];
}

- (void)centerScrollViewContents {
CGSize boundsSize = self.scrollView.bounds.size;
//NSLog(@"boundsSize: %@", NSStringFromCGSize(boundsSize));
CGRect contentsFrame = self.imageHolder.frame;
//NSLog(@"contentsFrame: %@", NSStringFromCGRect(contentsFrame));

if (contentsFrame.size.width < boundsSize.width) {
    contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
    contentsFrame.origin.x = 0.0f;
}

if (contentsFrame.size.height < boundsSize.height) {
    contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
    contentsFrame.origin.y = 0.0f;
}

self.imageHolder.frame = contentsFrame;
}

#pragma mark - UIScrollViewDelegate

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// Return the view that we want to zoom
return self.imageHolder;
//return self.scrollViewBar;
}

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
// The scroll view has zoomed, so we need to re-center the contents
[self centerScrollViewContents];
    }

Any help on this would be great. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:17:07+00:00Added an answer on June 15, 2026 at 1:17 am

    So, I found the solution myself. For some reason, as I wrote in my update to the question, any zooming in, followed by zooming out of the image fixed the image problem and presented it properly. I added these two lines to viewWillAppear, above [self centerScrollViewContents];

    self.scrollView.zoomScale = 2.0;
    self.scrollView.zoomScale = 1.0;
    

    Problem solved

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView with the following code: - (void)viewDidLoad { [super viewDidLoad]; parser
I have the following code in my viewDidLoad to change an image: - (void)viewDidLoad
I have the following code in ViewDidLoad of my UiTableViewController: UIImage *noImage = [UIImage
I have the following code in my viewDidLoad method. This is a uiviewcontroller with
In my viewDidLoad method of my iPhone app I have the following code: zombie[i].animationImages
I have following code for loading image from url in xml parsing endElement method
I have the following code in place: - (void)viewDidLoad { NSString *homeDirectoryPath = NSHomeDirectory();
I have the following code in viewDidLoad (to set a title in the nav
I have used the following code : NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
I have the following code: @interface NeighborProfileViewController : UIViewController { UIImageView * profPic; UITextView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.