我已经创建了一个自定义UIViewControllerAnimationTransition
类,并且需要在切换标签时将其设置为UITabBarController
。
tabBarController
不使用常规标签栏。我有一个类似于它的自定义实现,当按下按钮时,它会调用以下代码:
tabBarController.selectedIndex = index
目前我有tabBarController
(子类)作为其自己的transitionDelegate
的委托。但是,委托方法animationControllerForPresentedController
实际上从未被调用过。
标签栏控制器是否可以成为自己的委托?如果是这样,为什么转换代码从未实际调用过?
答案 0 :(得分:14)
animationControllerForPresentedController
是标签栏控制器的错误方法。
在UITabBarController子类中,采用UITabBarControllerDelegate
协议并将其设置为自己的delegate
。然后,使用tabBarController: animationControllerForTransitionFromViewController: toViewController:
返回自定义UIViewControllerAnimatedTransitioning
对象。
要获得更好的可视化效果,请查看TabBarDemo文件夹中的VCTransitionsLibrary。
答案 1 :(得分:0)
您是否使用过这样的委托方法?
@interface BTSlideInteractor : NSObject <UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate>
- (IBAction)showModalButtonWasTouched:(id)sender
{
BTSlideInteractor *interactor = [[BTSlideInteractor alloc] init];
interactor.presenting = YES;
BTModalViewController *modalController = [self.storyboard instantiateViewControllerWithIdentifier:@"ModalViewController"];
modalController.modalPresentationStyle = UIModalPresentationCustom;
modalController.transitioningDelegate = interactor;
[self presentViewController:modalController animated:YES completion:nil];
}
使用此链接参考:https://github.com/brightec/CustomViewControllerTransition/blob/master/test/BTViewController.m
如果您没有找到解决方案,请添加您的代码。