Question

I'm pushing ViewControllers on NavigationController by segues. I have my own subclassed NavigationController which has inserted UIImageView at index 0 - it's a background for my entire application.

The problem is that I can see that when new view controller is coming to the screen from the right side, in the beginning it's like having some light dark overlay which is disappearing when just after viewDidApear is called.

Every view controller has a self.view.backgroundColor = [UIColor clearColor]. If i change it for while, everything is fine. Maybe i should set background of application in another way? And if not, how to avoid this darkling effect?

Here you have screen capture with this effect: http://tinypic.com/r/34j9ffs/8

Was it helpful?

Solution

It's because of the standard UINavigationController push animation in iOS 7. When a new VC is pushed onto the stack, it overlays itself on top of the previous VC, with a slight shadow underneath it. As such, when you push your viewControllers which have clear backgrounds, you see through to the shadow when the transition takes place.

There are a couple of possible solutions:

  • Set a background colour on your viewControllers (probably not an option for you because of your global background image). The simplest solution, but would require a change to your design.
  • Implement your own transition using the new iOS 7 APIs. See an example here and an article from Big Nerd Ranch here. This is really the 'proper' solution to your problem if you want to keep your background image.
  • Add a UINavigationController category to add a simpler 'retro' push and pop animation, as per this answer. This is more of a quick and hacky solution.

OTHER TIPS

I created a custom push segue that should do the job:

ClearBkgPushSegue.h:

#import <UIKit/UIKit.h>

@interface ClearBkgPushSegue : UIStoryboardSegue

@end

ClearBkgPushSegue.m:

#import "ClearBkgPushSegue.h"

@implementation ClearBkgPushSegue


-(void)perform {
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destinationViewController = self.destinationViewController;

    CGRect bounds = [[UIScreen mainScreen] bounds];
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];

    UIView *destView = destinationViewController.view;
    [window insertSubview:destinationViewController.view aboveSubview:sourceViewController.view];

    destView.frame = CGRectMake(bounds.size.width, destView.frame.origin.y, destView.frame.size.width, destView.frame.size.height);
    [UIView animateWithDuration:.35 delay:0 options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         destView.frame = sourceViewController.view.frame;
                         sourceViewController.view.frame = CGRectMake([UIScreen mainScreen].bounds.size.width * -0.33, 0.0, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
                         sourceViewController.view.alpha = 0;
                     } completion:^(BOOL finished) {
                        [sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
                         sourceViewController.view.alpha = 1;

    }];


}

@end

Just select your segue to be "Custom" and choose this class and you're good to go.

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