Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Ribbit - Image View Controller Issues

Hi there,

I've completed the Ribbit (Self Destructing Image Project) and currently doing a little cleaning up.

On the Image View Controller that actually shows the image, it isn't displaying nicely. There's a huge white gap at the bottom... how can I expand the image to cover this? Also, sometimes the dimensions of the photo seems squashed? (e.g. the image isn't maintaining it's ratio)?

Any help on both of these would be appreciated. Please see screenshot and code below:

#import "XYZImageViewController.h"

@interface XYZImageViewController ()

@end

@implementation XYZImageViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    PFFile *imageFile = [self.message objectForKey:@"file"];
    NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
    NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];
    self.imageView.image = [UIImage imageWithData:imageData];

    NSString *senderName = [self.message objectForKey:@"senderName"];
    NSString *title = [NSString stringWithFormat:@"Sent from %@", senderName];
    self.navigationItem.title = title;
}

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

    if ([self respondsToSelector:@selector(timeout)]) {
        [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
    }
    else {
        NSLog(@"Error: selector missing");
    }
}

#pragma mark - Helper Methods

- (void)timeout {
    [self.navigationController popViewControllerAnimated:YES];
}

@end

2 Answers

thats because the image you saved to parse was resized to the size of the iphone4 screen. In your camera view controller in the imagePicker didFinishPickingMediaWithInfo you can change the values you resized your image to to 320 x 480 instead of what you previously had.

Genius! Thanks. Going to give it a go.

Does that flip the problem onto users that have a different screen size? Is there no solution that means the image is resized but maintains its core ratios?

that depends on how you have your imageView configured. You can change this around in your storyboard by selected your imageView then in the utilities view under view mode. scale to fill might be the default im not sure, you can change it around and see what works best. since the aspect ratios are different aspect fit/fill probably wont work as well, scale to fill is going to shrink the height down a bit.