iOS 7 shows black background in custom animation for Navigation - ios

I am using custom animation for navigation in my iOS app.
I have a subclass of UINavigationController in which the following methods are overridden:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:#"Push"];
[super pushViewController:viewController animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:#"Pop"];
UIViewController *poppedVC = [super popViewControllerAnimated:NO];
return poppedVC;
}
I don't remember the link but I had copied this code from a question in here and a little modification had worked for me.
Now when I ported my code to iOS 7 SDK, there is a black background shown while navigation.
I posted a video here: Black background while navigation in iOS app to make it clear.
Note: The requirement in my app is that animation be the opposite of the default right-left and left-right when push/pop. This code was working perfectly when I was targeting iOS 5 and there was not black background/screen shown.

Add in the delegate (didFinishLaunchingWithOptions method) these two lines :
self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor whiteColor];

Okay, since I couldn't find a feasible solution to this problem. I did a couple of things as work around and now the animation seems to much better than previous.
I set bar tint color and background color for UINavigationBar to be the same.
UIColor *navigationBarColor = UIColorFromHexRGB(0x0473C0);
[[UINavigationBar appearance] setBarTintColor:navigationBarColor];
[[UINavigationBar appearance] setBackgroundColor:navigationBarColor];
During navigation there was black space being shown on top in place of status bar.
I did this:
UIView *hackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
hackView.backgroundColor = navigationBarColor;
[self.window addSubview:hackView];
Note that this color is the same as for the navigation bar.
I have a common background color used for all the views in the app. To remove the black background being shown during navigation, I did this:
UIImage *backgroundImage = [UIImage imageNamed:#"viewbackground.png"];
UIColor *bgColor = [UIColor colorWithPatternImage:backgroundImage];
[self.window setBackgroundColor:bgColor];
[self.window setTintColor:bgColor];
Video uploaded here.

Related

Black effect when screen popping controller with custom animation?

I am popping a view controller from navigation controller.When i am popping controller i want to give it animation like Pushing a view controller.For that purpose i am using below code
CATransition* transition = [CATransition animation];
transition.duration = 0.3f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.appDelegate setUpForLVC];
[self.navigationController popViewControllerAnimated:NO];
When animation starts i get black effect here.Please tell me what is the issue with my code ?
add this code in didFinishLaunchingWithOptions
self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor whiteColor];
**OR**
2)Set animation duration to 0

How to Push a ViewController from Left Over another

I want to make a Navigation Drawer Like This:
I saw many third party libararies. But I want to do it from my own.
Here is what I am trying :
__block UIViewController *sourceViewController = self;
NavigationDrawerVC *controller = [[NavigationDrawerVC alloc] initWithNibName:#"NavigationDrawerVC" bundle:nil];
__block UIViewController *destinationController = (UIViewController*)controller;
CATransition* transition = [CATransition animation];
transition.duration = 5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
But I am getiing o/p like this:
When I click on Button My Screen Changes Like this:
My Previous VIewController also moving.
I want to make it Fix. And also I am not able to stop it at certain point.
You might want to look into using a child controller for this.
Here's a very simplified code which demonstrates this concept. It adds a child view controller and animates it to the middle of the screen. This should at least give you a starting point:
UIViewController *drawerVC = [[UIViewController alloc] init];
drawerVC.view.backgroundColor = [UIColor redColor];
[self addChildViewController:drawerVC];
drawerVC.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:drawerVC.view];
[drawerVC didMoveToParentViewController:self];
[UIView animateWithDuration:0.3 animations:^{
drawerVC.view.frame = CGRectOffset(drawerVC.view.frame, drawerVC.view.frame.size.width * 0.5, 0);
}];

CATransition working wrong on orientation change before dismissing a NavigationViewController

Here is my code used to present a navigationViewController :
-(IBAction)showFilterView:(id)sender {
FilterViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:#"FilterViewController"];
UINavigationController *nvc=[[UINavigationController alloc] initWithRootViewController:vc];
CATransition *transition = [CATransition animation];
transition.duration = 0.35;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromLeft;
UIView *containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil];
[self.tabBarController presentViewController:nvc animated:NO completion:nil];
}
And here is my code to dismiss
-(IBAction)back:(id)sender {
CATransition *transition = [CATransition animation];
transition.duration = 0.35;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
UIView *containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil];
[[self.navigationController presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
Situation 1 --- Working well in landscape mode
Situation 2 --- Working well in portrait mode
Situation 3 --- Presenting in a portrait mode and dismissing in landscape mode not working properly(extra animation before displaying correct view)
Situation 4 ---Presenting in a landscape mode and dismissing in portrait mode not working properly(extra animation before displaying correct view)
The UIWindow layer has weird rotation properties and any animations you perform aren't guaranteed to correctly detect orientation (and vary with different iOS versions). The easiest way to do what you're trying to is with a custom presentation animation. This is a good writeup of how to do it.

UINavigationBar fades when pushing/popping

I am using the old (pre-iOS7) push/pop animation by using the method described here:
#implementation UINavigationController (Retro)
- (void)pushViewControllerRetro:(UIViewController *)viewController {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation:transition forKey:nil];
[self pushViewController:viewController animated:NO];
}
- (void)popViewControllerRetro {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:transition forKey:nil];
[self popViewControllerAnimated:NO];
}
#end
My problem is that iOS7 seems to fade the UINavigationBar of the previous view controller when pushing a new view controller. Normally this looks fine because iOS 7 is dragging the views on top of each other. But when I am using the pre-iOS7 animation it gives me a short flash, because the navigation bar fades while the new view it getting pushed in from the right side.
Is there a way to disable the fade animation on the navigation bar?

Multiple fades in a CATTransition

I'm using a CATransition to create a fade effect on the pushViewControllerAnimated of a UINavigationViewController. This worked out fine with the following code:
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;
[navController.view.layer addAnimation:transition forKey:kCATransition];
[navController popViewControllerAnimated:NO];
[navController pushViewController:nieuweDetailPagina animated:NO];
But because my views are very similar I would like to fade to white in between or show a white flash.
Is it posible to do it in the same transition or do I have to creat a UIView with a white background and start a simultanious animation?
Cheers!

Resources