gpt4 book ai didi

ios - 动画化 UITabBarController 导航

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:49 27 4
gpt4 key购买 nike

我目前遇到有关动画的 iOS 开发问题。我目前正在使用以下代码制作一个“幻灯片动画”,用于在手势识别器触发后切换标签栏项目。

-(void)slideToTab:(int)controllerIndex
{
if(controllerIndex >= 0 && controllerIndex < [self.tabBarController.viewControllers count])
{
// Get the views.
UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:controllerIndex] view];

// Get the size of the view area.
CGRect viewSize = fromView.frame;
BOOL scrollRight = controllerIndex > self.tabBarController.selectedIndex;

// Add the to view to the tab bar view.
[fromView.superview addSubview:toView];

// Position it off screen.
toView.frame = CGRectMake((scrollRight ? 320 : -320), viewSize.origin.y, 320, viewSize.size.height);

[UIView animateWithDuration:0.3
animations: ^{

// Animate the views on and off the screen. This will appear to slide.
fromView.frame =CGRectMake((scrollRight ? -320 : 320), viewSize.origin.y, 320, viewSize.size.height);
toView.frame =CGRectMake(0, viewSize.origin.y, 320, viewSize.size.height);
}

completion:^(BOOL finished) {
if(finished)
{
// Remove the old view from the tabbar view.
[fromView removeFromSuperview];
self.tabBarController.selectedIndex = controllerIndex;
}
}];
}
}

对于选项卡栏上的选项卡栏项目,此代码工作正常,但每当我点击位于选项卡栏“更多”部分的第一个选项卡时,动画停止工作并且完成 block 中的完成 bool 值返回错误的。为什么这会发生在选项卡栏的“更多”部分?有什么可能的解决方案吗?

最佳答案

在 iOS 6 下不正式支持实现自定义标签栏转换,但在 iOS 7 下,您可以让标签栏的委托(delegate)实现

-tabBarController:animationControllerForTransitionFromViewController:toViewController:

并返回一个实现

的对象
-transitionDuration and -animateTransition:

将执行转换。

关于ios - 动画化 UITabBarController 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18834249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com