Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After multiple trials here is how I got it working for what I wanted. This is what I was trying. - I have a view with a image. and I wanted to have the image go full screen. - I have a navigation controller with a tabBar too. So i need to hide that too. - Also, my main requirement was not just hiding, but having a fading effect too while showing and hiding.</p> <p>This is how I got it working. </p> <p>Step 1 - I have a image and user taps on that image once. I capture that gesture and push it into the new <code>imageViewController</code>, its in the <code>imageViewController</code>, I want to have full screen image.</p> <pre><code>- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { NSLog(@"Single tap"); ImageViewController *imageViewController = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil]; godImageViewController.imgName = // pass the image. godImageViewController.hidesBottomBarWhenPushed=YES;// This is important to note. [self.navigationController pushViewController:godImageViewController animated:YES]; // If I remove the line below, then I get this error. [CALayer retain]: message sent to deallocated instance . // [godImageViewController release]; } </code></pre> <p>Step 2 - All these steps below are in the ImageViewController</p> <p>Step 2.1 - In ViewDidLoad, show the navBar</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSLog(@"viewDidLoad"); [[self navigationController] setNavigationBarHidden:NO animated:YES]; } </code></pre> <p>Step 2.2 - In <code>viewDidAppear</code>, set up a timer task with delay ( I have it set for 1 sec delay). And after the delay, add fading effect. I am using alpha to use fading.</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { NSLog(@"viewDidAppear"); myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; } - (void)fadeScreen { [UIView beginAnimations:nil context:nil]; // begins animation block [UIView setAnimationDuration:1.95]; // sets animation duration self.navigationController.navigationBar.alpha = 0.0; // Fades the alpha channel of this view to "0.0" over the animationDuration of "0.75" seconds [UIView commitAnimations]; // commits the animation block. This Block is done. } </code></pre> <p>step 2.3 - Under <code>viewWillAppear</code>, add singleTap gesture to the image and make the navBar translucent. </p> <pre><code>- (void) viewWillAppear:(BOOL)animated { NSLog(@"viewWillAppear"); NSString *path = [[NSBundle mainBundle] pathForResource:self.imgName ofType:@"png"]; UIImage *theImage = [UIImage imageWithContentsOfFile:path]; self.imgView.image = theImage; // add tap gestures UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [self.imgView addGestureRecognizer:singleTap]; [singleTap release]; // to make the image go full screen self.navigationController.navigationBar.translucent=YES; } - (void)handleTap:(UIGestureRecognizer *)gestureRecognizer { NSLog(@"Handle Single tap"); [self finishedFading]; // fade again. You can choose to skip this can add a bool, if you want to fade again when user taps again. myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; } </code></pre> <p>Step 3 - Finally in <code>viewWillDisappear</code>, make sure to put all the stuff back </p> <pre><code>- (void)viewWillDisappear: (BOOL)animated { self.hidesBottomBarWhenPushed = NO; self.navigationController.navigationBar.translucent=NO; if (self.navigationController.topViewController != self) { [self.navigationController setNavigationBarHidden:NO animated:animated]; } [super viewWillDisappear:animated]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload