How to get original image when we zoom in and zoom out the image in ios

0 votes

Hi i am beginner in ios and in my project i am adding UIImage on UIScrollview and i have added tap gesture on UIImage

When we double click on UIImage then image should be zooming full screen size on view controller

After the full screen size image we can zoom it like any way what we want(i mean using like pinch zoom effect)here my requirement is when we double click on image then image need to set it's original position i have tried my level best but i did not get result please help me

my code is below:

#import "ViewController2.h"

@interface ViewController2 ()
{
    UIScrollView * myScroll;
    UITapGestureRecognizer *tap;
    BOOL isFullScreen;
    CGRect prevFrame;
    UIImageView * _imageView;
}

@end

@implementation ViewController2

- (void)viewDidLoad
{
    [super viewDidLoad];

    isFullScreen = FALSE;
    myScroll = [[UIScrollView alloc] init];
    myScroll.frame = self.view.bounds;
    myScroll.contentSize = CGSizeMake(_imageView.frame.size.width, _imageView.frame.size.height);
    myScroll.maximumZoomScale = 4.0;
    myScroll.minimumZoomScale = 1.0;
    myScroll.clipsToBounds = YES;
    myScroll.delegate = self;
    myScroll.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:myScroll];

    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    [_imageView setClipsToBounds:YES];
    _imageView.userInteractionEnabled = YES;
    _imageView.image = [UIImage imageNamed:@"ram.jpeg"];

    UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen:)];
    tapper.numberOfTapsRequired = 1;
    [_imageView addGestureRecognizer:tapper];
    [myScroll addSubview:_imageView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    return _imageView;
}

-(void)imgToFullScreen:(UITapGestureRecognizer*)sender {

    if (!isFullScreen) {

        [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{

            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;
    }
}

@end


 

Nov 17, 2022 in Mobile Development by gaurav
• 23,260 points
679 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Mobile Development

0 votes
0 answers

How to fetch the width and height of a programatically added view in Swift/ iOS?

I have added a UIView and a ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
1,104 views
0 votes
1 answer

How to get the user's country calling code in iOS?

Import Statement : #import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> you can get country ...READ MORE

answered Dec 15, 2022 in Mobile Development by gaurav
• 23,260 points
1,201 views
0 votes
0 answers

How to receive single tap and hold Remote-Control Event with iOS

I'm looking for my app to listen ...READ MORE

Nov 8, 2022 in Mobile Development by gaurav
• 23,260 points
440 views
0 votes
0 answers

How to draw heart shape in UIView (iOS)?

I want to create different shapes. Below ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
659 views
0 votes
0 answers
0 votes
0 answers
0 votes
1 answer

Get User Group in Swift using AWS Cognito

The groups are exposed in the ID ...READ MORE

answered Nov 12, 2018 in AWS by Priyaj
• 58,020 points
1,548 views
0 votes
1 answer

URL Scheme for iOS Home App

I think you could try doing it ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,154 views
0 votes
1 answer

iOS App : Porting Code to App

If you make a post, missing parameters ...READ MORE

answered Jan 18, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
645 views
0 votes
1 answer

swift for windows? xcode on windows? ?

Hi, @Aminegac, If you’re a little more technically ...READ MORE

answered Dec 4, 2020 in Others by Nikita
1,774 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP