IOS 7 shows a black background in custom animations for navigation

I am using custom animation for navigation in my iOS app.

I have a subclass of UINavigationController that overrides the following methods:

 - (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 copied this code from the question here, and a small modification worked for me.

Now that I have ported my code to the iOS 7 SDK, a black background is displayed during navigation.

I posted a video here: Black background while navigating an iOS app to make it clear.

Note. The requirement in my application is that the animation will be opposite right and left and right right by default when push / pop. This code worked fine when I focused on iOS 5 and it didn't have a black background / screen.

+6
source share
2 answers

Add the following two lines to the delegate (didFinishLaunchingWithOptions method):

 self.window.backgroundColor = [UIColor whiteColor]; self.window.tintColor = [UIColor whiteColor]; 
+5
source

Good, since I could not find an acceptable solution to this problem. I did a couple of things like work, and now the animation seems a lot better than the previous one.

I set the tone color and background color for the UINavigationBar to be the same.

 UIColor *navigationBarColor = UIColorFromHexRGB(0x0473C0); [[UINavigationBar appearance] setBarTintColor:navigationBarColor]; [[UINavigationBar appearance] setBackgroundColor:navigationBarColor]; 

During navigation, a black space was shown in the status bar.

I have done this:

 UIView *hackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)]; hackView.backgroundColor = navigationBarColor; [self.window addSubview:hackView]; 

Please note that this color is the same as for the navigation bar.

I have a common background color used for all views in the application. To remove the black background displayed during navigation, I did the following:

 UIImage *backgroundImage = [UIImage imageNamed:@"viewbackground.png"]; UIColor *bgColor = [UIColor colorWithPatternImage:backgroundImage]; [self.window setBackgroundColor:bgColor]; [self.window setTintColor:bgColor]; 

Video uploaded here .

+3
source

Source: https://habr.com/ru/post/958393/


All Articles