2016-07-21 29 views
0

我想創建一個自定義的tabbar動畫,當用戶點擊選項卡欄按鈕。iOS/Objective c - UITabBarControllerDelegate - 自定義選項卡動畫代理不叫

我已經實現了實現UITabBarControllerDelegate

這裏是.M

#import "MYCustomTabBarControler.h" 


@interface MYCustomTabBarControler() 

@end 

@implementation MYCustomTabBarControler 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.delegate = self; // I set the delegate as self 

} 


#pragma mark - UITabBarControllerDelegate 

- (BOOL)tabBarController:(UITabBarController *)tabBarController 
shouldSelectViewController:(UIViewController *)viewController { 

    //This is called so I know the delegate is working 
    NSLog(@"The tabBarController delegate is set and working"); 
    return YES; 
} 

//This delegate method is never called 
- (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController 
      UIViewControllerAnimatedTransitioning:(UIViewController *)fromVC 
              toViewController:(UIViewController *)toVC { 


    MYBarTransition *animator = [MYBarTransition new]; 
    return animator; 

} 

//This delegate method is never called 
- (id<UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController 
        interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController { 

    MYBarTransition *animator = [MYBarTransition new]; 
    return animator; 
} 

出於某種原因,負責過渡的委託方法是不叫的UITabBarController的子類。我已閱讀docs,並且看不到任何他們不會被調用的原因。

我已正確設置我的委託,並證實了它是 通過實現shouldSelectViewController方法

缺少什麼我在這裏工作?

+0

你預計什麼時候叫它? – beyowulf

+0

當用戶點擊標籤欄按鈕時不應該調用它嗎? – Zigglzworth

+0

我希望當用戶點擊標籤欄按鈕時會調用它..但它不是 – Zigglzworth

回答

3

我認爲你正在使用錯誤的委託方法來完成你正在做的事情。嘗試使用:

- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController 
      animationControllerForTransitionFromViewController:(UIViewController *)fromVC 
               toViewController:(UIViewController *)toVC; 

當用戶點擊不同的選項卡時會調用這個選項。

+0

LOL。是。我會在幾個小時內蒙羞 – Zigglzworth