【问题标题】:iOS / Objective c - UITabBarControllerDelegate - Custom tab animation delegates not callediOS / Objective c - UITabBarControllerDelegate - 未调用自定义选项卡动画委托
【发布时间】:2016-07-21 21:27:39
【问题描述】:

当用户点击标签栏按钮时,我正在尝试创建自定义标签栏动画。

我已经实现了一个实现 UITabBarControllerDelegate 的 UITabBarController 子类

这是.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;
}

由于某种原因,负责转换的委托方法没有被调用。我已经阅读了docs 并且看不出他们不会被调用的任何原因。

我已正确设置我的委托并确认它是 通过实现 shouldSelectViewController 方法来工作

我在这里错过了什么?

【问题讨论】:

  • 你希望它什么时候被调用?
  • 用户点击标签栏按钮时不应该调用它吗?
  • 我希望它在用户点击标签栏按钮时被调用.. 但它不是

标签: ios objective-c uitabbarcontroller uiviewanimation


【解决方案1】:

我认为您尝试完成的任务使用了错误的委托方法。尝试使用:

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

当用户点击不同的标签时会调用它。

【讨论】:

  • 哈哈。是的。我要羞愧地躺几个小时
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多