سؤال

One element of the application I am making has a ViewController which presents the user with an image thumbnail and some details. What I want to happen is when the user clicks the image it full screens to its original size (whether that be portrait or landscape). When the user taps again it will minimise the image back down to a thumbnail.

I currently have the tap function working so it fullscreens on tap and then minimises on tap again but it has a few issues.

It seems to stretch the image too much and if its a landscape image it will just stretch it portrait anyway. Also the thumbnail is in a UIScrollView, so when it zooms in the image sometimes, it does not centre it and you can still scroll, when its full screened. Can I have some help/advise on this please, Im stuck on what to do. I want to have it similar to how it works on the Twitter app, if thats any help. I am fairly new to iOS Development too.

Below is my code for when a tap is executed:

-(IBAction)tap:(id)sender {

    //goto new ViewController and set the image

    if (!isFullScreen) {
        [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
            //save previous frame
            prevFrame = _imageView.frame;            
            [_imageView setFrame:[[UIScreen mainScreen] bounds]];
        }completion:^(BOOL finished){
            isFullScreen = TRUE;
        }];
        return;
    } else {
        [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
            [_imageView setFrame:prevFrame];
        } completion:^(BOOL finished){
            isFullScreen = FALSE;
        }];
        return;
    }
}
هل كانت مفيدة؟

المحلول

Try imageView.contentMode = UIViewContentModeScaleAspectFit; and place this where ever you initialize your image view.

نصائح أخرى

To eliminate the stretching issue I used (provided by Milo):

imageView.contentMode = UIViewContentModeScaleAspectFit;

In terms of the centring and overall approach to full-screening the image, I have taken Leo's advice and will use a View Controller modally.

Thanks Guys!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top