[英]How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate
I'm trying to animate the transitions between tabs in my UITabBarController, which is working fine when I push on the tab buttons. 我正在尝试为我的UITabBarController中的选项卡之间的过渡设置动画,当我按下选项卡按钮时,它可以正常工作。 However, when I switch tabs programmatically by calling
但是,当我通过调用以编程方式切换选项卡时
[self.tabBarController setSelectedIndex:2];
in a swipe gesture recognizer, the shouldSelectViewController function is NOT being called in my UITabBarControllerDelegate delegate, and therefore my animation isn't being triggered. 在滑动手势识别器中,未在UITabBarControllerDelegate委托中调用shouldSelectViewController函数,因此不会触发我的动画。
Is there a way to accomplish what I want? 有没有办法实现我想要的? Can I programmatically trigger the tab switch differently perhaps so that the shouldSelectViewController function gets called?
我是否可以通过编程方式以其他方式触发选项卡开关,以便调用shouldSelectViewController函数?
If you have implemented - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
in your tabBarController's delegate than you can call it manually. 如果已在
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
的委托中实现- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
,则可以手动调用它。
[self.tabBarController.delegate tabBarController:self.tabBarController shouldSelectViewController:[[tabBar viewControllers] objectAtIndex:2]];
[self.tabBarController setSelectedIndex:2];
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.