首先,我是初学者。请原谅我这个愚蠢的问题。
我使用UITabBarController
创建了两个子页面,第一页包含UIButton
,而alsl我创建了另一个页面(DetailPage)。我将按钮和DetailPage
连接到segue。但是segue的样式不能设置为push
。(这会触发错误,push
样式仅用于UINavigatorController
)。
那么,当我单击按钮时,如何使用PUSH样式导航到DetailPage?
我尝试了一种新方法,使用UINavigatorController
管理第一页和DetailPage,然后将此UINavigatorController
嵌入UITabItem
。当我完成此操作后,我可以使用push
样式导航到DetailPage。但是另一个问题是,当导航DetailPage时,TabBar始终保持在页面底部。我想将所有UITabBarController
推到左侧。
我想要的效果如下图:
如何优化代码?
答案 0 :(得分:0)
实现这样的委托(UITabBarControllerDelegate)方法:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
NSArray *tabViewControllers = tabBarController.viewControllers;
UIView * fromView = tabBarController.selectedViewController.view;
UIView * toView = viewController.view;
if (fromView == toView)
return false;
NSUInteger fromIndex = [tabViewControllers indexOfObject:tabBarController.selectedViewController];
NSUInteger toIndex = [tabViewControllers indexOfObject:viewController];
[UIView transitionFromView:fromView
toView:toView
duration:0.3
options: toIndex > fromIndex ? UIViewAnimationOptionTransitionFlipFromLeft : UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
if (finished) {
tabBarController.selectedIndex = toIndex;
}
}];
return true;
}
这是翻转动画改变动画
推送:
CATransition* transition = [CATransition animation];
[transition setDuration:0.3];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setFillMode:kCAFillModeBoth];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:transition forKey:kCATransition];
对于Pop:
CATransition* transition = [CATransition animation];
[transition setDuration:0.3];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setFillMode:kCAFillModeBoth];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:transition forKey:kCATransition];
现在由你决定,祝你好运....