簡體   English   中英

從右向左推送動畫會導致導航欄損壞

[英]Right To Left Push animation results in corrupted navigation bar

我將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.

我已經研究了這些錯誤,並發現了一個阻止您接收它們的類: 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

我不知道如果要創建自定義的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值來更改過渡的方向。(我可能設置了錯誤的子類型的值,我不斷混合它們)

您也可以使用相同的方法來pop視圖控制器。 一世

而且,如果您想使用segue,可以使用它,只需創建一個自定義segue並通過添加前面的代碼並添加一些附加內容來覆蓋-(void)perform方法,則必須使用[self sourceViewController];獲取視圖控制器[self sourceViewController]; [self destinationViewController];

對我來說,問題是一個接一個地推動控制器,一個接一個地引起了幾個過渡動畫。 這個鏈接對我有幫助: https : //github.com/Plasma/BufferedNavigationController/blob/master/BufferedNavigationController.m

我從這個堆棧溢出的答案了吧: iOS版:popViewController意外的行為

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM