向右推动animation导致损坏的导航栏
我UINavigationController
inheritance从UIRTLNavigationController.m执行从右到左(不正常行为)推我已经添加在这个问题的底部,并得到这些警告:
nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
我已经研究了这些错误,发现一个类阻止你接收它们: https : //github.com/Plasma/BufferedNavigationController
我已经将BufferedNavigationController .h和.m添加到我的项目中,将BufferedNavigationController.h中的行更改为:@interface BufferedNavigationController:UIRTLNavigationController,并将BufferedNavigationController设置为IB中的UINavigationController
自定义子类。
视图仍然从右到左,方法被调用内部BufferedNavigationController,但我仍然得到有关嵌套和..Navigation Bar子视图树可能会损坏的警告..
任何帮助,将不胜感激。
UIRTLNavigationController.m:
#import "UIRTLNavigationController.h" @implementation UIRTLNavigationController - (id)initWithRootViewController:(UIViewController *)rootViewController { self = [super initWithRootViewController:rootViewController]; if (!self) return nil; return self; } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { NSLog(@"pushViewController"); // Add the viewController and a fake controller without animation. Then pop the fake controller with animation. UIViewController *fakeController = [[[UIViewController alloc] init] autorelease]; [super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO]; [super popViewControllerAnimated:animated]; } - (void)popViewControllerAnimatedStep2:(UIViewController *)viewController { // Push the new top controller with animation [super pushViewController:viewController animated:YES]; // Remove the view that should have been popped NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]]; [arr removeObjectAtIndex:[[self viewControllers] count]-2]; [super setViewControllers:[NSArray arrayWithArray:arr] animated:NO]; } - (UIViewController *)popViewControllerAnimated:(BOOL)animated { NSLog(@"popViewControllerAnimated"); if (animated) { // Save the controller that should be on top after this pop operation UIViewController *newTopController = [[self viewControllers] objectAtIndex:[[self viewControllers] count]-2]; // Remove it from the stack. Leave the view that should be popped on top NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]]; [arr removeObjectAtIndex:[[self viewControllers] count]-2]; [super setViewControllers:[NSArray arrayWithArray:arr] animated:NO]; // Schedule the next step [self performSelector:@selector(popViewControllerAnimatedStep2:) withObject:newTopController afterDelay:0]; return [arr objectAtIndex:[arr count]-1]; } return [super popViewControllerAnimated:NO]; } - (void)dealloc { [super dealloc]; } @end
我不知道你是否创build自定义的UINavigationController只是为了执行一个自定义的过渡,如果你这样做,有一个更简单的方法来做到这一点。 像下面的代码一样
-(void)makeMyCustomAnimation { YourDestinationViewController *destinationController = [YourDestinationViewController alloc] initWithNib.....];//add the missing code fot ini CATransition* transition = [CATransition animation]; transition.duration = .25; //you can change this value to fit your needs transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; //kCAMediaTimingFunctionLinear //kCAMediaTimingFunctionEaseIn //kCAMediaTimingFunctionEaseOut //kCAMediaTimingFunctionEaseInEaseOut //kCAMediaTimingFunctionDefault transition.type = kCATransitionPush; //kCATransitionMoveIn; //kCATransitionPush, //kCATransitionReveal //kCATransitionFade transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft, //kCATransitionFromRight //kCATransitionFromTop, //kCATransitionFromBottom [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; [self.navigationController pushViewController:destinationController animated:NO];
}
你可以通过改变subtype
值来改变你的转换方向(我可能会设置错误的子types值,我会继续混合它们)
你也可以使用相同的方法来pop
视图控制器。 一世
如果你想使用segues,只需要创build一个自定义的segue,并且通过添加前面的代码来添加-(void)perform
方法,就必须使用[self sourceViewController];
来获得视图控制器[self sourceViewController];
和[self destinationViewController];
对我来说,问题是一个接一个地推动控制器,一个接一个地导致了几个过渡animation。 这个链接帮助了我: https : //github.com/Plasma/BufferedNavigationController/blob/master/BufferedNavigationController.m
我从这个堆栈溢出中得到了答案: iOS:popViewController出乎意料的行为
- 访问容器视图控制器
- 如何将UIColor值转换为指定的颜色string?
- 目前MFMailComposeViewController从模态FormSheet在iPad上?
- ViewController从NavigationController中移除后,AVPlayer继续播放
- 使用iOS 10中的UNNotificationSettings检查通知types
- 为什么一个崩溃日志象征性而不是另一个?
- UIImagePickerController:检查返回的图像是横向还是纵向?
- 用CocoaTouchFramework中的CocoaPods 0.36.0与Swift一起使用
- 不在背景上调用CLLocationManager委托方法