简体   繁体   English

用于UITabBarController动画的Transition Delegate

[英]Transition Delegate for UITabBarController animation

I have a custom UIViewControllerAnimationTransition class created already, and need to make this animate a UITabBarController when it switches tabs. 我已经创建了一个自定义的UIViewControllerAnimationTransition类,并且需要在切换选项卡时使其为UITabBarController设置动画。

The tabBarController does not use the regular tab bar, though. 但是, tabBarController不使用常规选项卡栏。 I have a custom implementation that acts like it, and when a button is pressed, it calls this code: 我有一个类似于它的自定义实现,当按下按钮时,它会调用以下代码:

tabBarController.selectedIndex = index

Currently I have the tabBarController (subclass) as the delegate for its own transitionDelegate . 目前我有tabBarController (子类)作为其自己的transitionDelegate的委托。 The delegate method animationControllerForPresentedController is never actually called, though. 但是,委托方法animationControllerForPresentedController实际上从未被调用过。

Is it fine for the tab bar controller to be its own delegate? 标签栏控制器是否可以成为自己的委托? If so, why is the transition code never actually called? 如果是这样,为什么转换代码永远不会被调用?

animationControllerForPresentedController is the wrong approach for the tab bar controller. animationControllerForPresentedController是标签栏控制器的错误方法。

In the UITabBarController subclass, adopt the UITabBarControllerDelegate protocol and set it as its own delegate . 在UITabBarController子类中,采用UITabBarControllerDelegate协议并将其设置为自己的delegate Then, use tabBarController: animationControllerForTransitionFromViewController: toViewController: to return the custom UIViewControllerAnimatedTransitioning object. 然后,使用tabBarController: animationControllerForTransitionFromViewController: toViewController:返回自定义UIViewControllerAnimatedTransitioning对象。

To get a better visualization, look at VCTransitionsLibrary in the TabBarDemo folder. 为了获得更好的可视化,看看VCTransitionsLibrary在TabBarDemo文件夹中。

Did you use these delegate methods like this? 您是否使用过这样的委托方法?

@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];
}

Use this link for Reference: https://github.com/brightec/CustomViewControllerTransition/blob/master/test/BTViewController.m 使用此链接参考: https//github.com/brightec/CustomViewControllerTransition/blob/master/test/BTViewController.m

If you didnt find the solution kindly add your codes. 如果您没有找到解决方案,请添加您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM