Ios 从右向左推送动画会导致导航栏损坏

Ios 从右向左推送动画会导致导航栏损坏,ios,objective-c,cocoa-touch,uinavigationcontroller,Ios,Objective C,Cocoa Touch,Uinavigationcontroller,我正在对我的UINavigationController进行子类化,以使用UIRTLNavigationController执行从右向左的推送(非正常行为)。m我在问题的底部添加了以下警告: nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree mi

我正在对我的
UINavigationController
进行子类化,以使用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.
我对这些错误进行了研究,发现有一个类阻止您接收这些错误:

我已将BufferedNavigationController.h和.m添加到我的项目中,将BufferedNavigationController.h中的行更改为: @接口缓冲导航控制器:UIRTLNavigationController 并将BufferedNavigationController设置为IB中的my
UINavigationController
自定义子类

视图仍在从右向左移动,在BufferedNavigationController中调用方法,但我仍然收到有关嵌套和..导航栏子视图树可能损坏的警告

任何帮助都将不胜感激

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

我不知道您是否只是为了执行自定义转换而创建自定义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];
}

您可以通过更改
子类型
值来更改转换的方向。(我可能设置了错误的子类型值,我会不断混合它们)

您也可以使用相同的方法来弹出视图控制器。我


如果您想使用segue,可以使用它,只需创建一个自定义segue并重写
-(void)perform
方法,通过添加一些附加内容来添加以前的代码,您必须使用
[self sourceViewController]获得视图控制器
[自定目标视图控制器]

对我来说,问题是一个接一个地推控制器,这导致了一个接一个的转换动画。这个链接帮助我:


我从堆栈溢出中得到答案:

谢谢你的回复。原因是自定义转换,您是正确的。我试着沿着CatTransition大道走,但无法摆脱分段之间的透明度。经过一点研究,我发现“最好”的解决方案是为每个
UIView
制作一个自定义的背景图像。请阅读这里:所以决定为什么选择上面的内容。哦,那么你的问题是,当视图被推/弹出时,
fade
效果如何?我的目标是有一个简单的从右到左的segua移动。对于CATTransition,我找不到一种没有淡入淡出效果的方法(除了我上面添加的链接),你是否尝试了一个自定义的推送序列,是否添加了相同的效果?是的<代码>CATTransition
总是伴随着令人讨厌的淡入淡出。