Question

I have an image view on a single page app and I set it to be fullscreen size when tap on it and it works. But I also want it to zoom out to its original size when tap on it when it is on fullscreen size. How to make it? Right now, tap it will make it fullscreen and then I can nothing but stop the running. Here is my code:

- (void)Enlarge:(id)sender{
    [ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)]; //enlarge to fullscreen but exclude the status bar.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Enlarge:)];
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.cancelsTouchesInView = YES;
    [ImageView setUserInteractionEnabled:YES];
    [ImageView addGestureRecognizer:tapGesture];
    [tapGesture release];
}

My second question is that I have two storyboards controlled by this viewcontroller, one for 3.5inch and another for 4inch screen. I want my enlarge to fit both screen size, can following change do the trick? cuz I don't have iPhone5 to test at this moment.

- (void)Enlarge:(id)sender{
    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    if (iOSDeviceScreenSize.height == 480){
        [ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)];
    }
    if (iOSDeviceScreenSize.height == 568){
        [ImageView setFrame:CGRectMake(0, 20, (548/1.775), 568-20)];
    }

}

Thanks a lot!

Was it helpful?

Solution

add a BOOL Variable to track if it's fullScreen.

in .h add property

@property (nonatomic, assign) BOOL isFullScreen;

@property (nonatomic, assign) CGRect originalRect;

in viewDidLoad, add these lines,

self.isFullScreen = NO;
self.originalRect = CGRectMake(0,0,153,230);//replace this by the zoomed out rect size that you want

and in your Enlarge:

- (void)Enlarge:(id)sender{

if(!self.isFullScreen){
[ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)]; //enlarge to fullscreen but exclude the status bar.
}else {
[ImageView setFrame:originalFrame];//
}
self.isFullScreen = !self.isFullScreen;
}

Regarding second question, Yes, that should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top