// pushViewController 动画
- (void)pushViewController:(NSString *)type andData:(NSDictionary *)data
{
//self.navigationController.navigationBarHidden = NO;
//推至推详情页
PushDetailViewController *viewController = [[PushDetailViewController alloc] init];
// PushDetailViewController *viewController = [[PushDetailViewController alloc] initWithNibName:@"PushDetailViewController" bundle:[NSBundle mainBundle]];
viewController.info = data;
//推入的页面不显示底部标签栏
viewController.hidesBottomBarWhenPushed = YES;
if ([type isEqualToString:@"no"]) {
[self.navigationController pushViewController:viewController animated:YES];
} else if ([type isEqualToString:@"view"]) { // 定义 viewController.view 视图动画
viewController.view.frame = CGRectMake(0.0f, -480.0f, 320.0f, 960.0f);
[self.navigationController pushViewController:viewController animated:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.3];
[UIView setAnimationDelegate:self];
//controller.view.center = CGPointMake(160.0f, 240.0f);
viewController.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
[UIView commitAnimations];
// [viewController release];
} else {
// 自定义动画
CATransition *transition = [CATransition animation];
// 动画时间
transition.duration = 0.5f;
// 动画时间控制
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// 是否代理
transition.delegate = self;
// 是否在当前层完成动画
// transition.removedOnCompletion = NO;
if ([type isEqualToString:@"3D"]) {
transition.type = @"cube";
transition.subtype = kCATransitionMoveIn;
} else {
// kCATransitionFade: Core Animation 交叉淡化过渡,新视图渐显示,旧视图渐淡出视野
// kCATransitionPush: Core Animation过渡,新视图将旧视图推出去。有4种方式 kCATransitionFromTop | kCATransitionFromLeft | kCATransitionFromBottom | kCATransitionFromRight
// kCATransitionMoveIn: Core Animation过渡,新视图移到旧视图上面。同上有4种方式
// kCATransitionReveal: Core Animation过渡,将旧视图移开显示出下面的新视图。同上有4种方式
// 动画类型
transition.type = kCATransitionReveal;
// 动画进入方式
transition.subtype = kCATransitionFromRight;
}
[self.navigationController pushViewController:viewController animated:NO];
// 动画事件
[self.navigationController.view.layer addAnimation:transition forKey:nil];
}
[viewController release];
}
// presentModalViewController 动画
- (void) presentModalViewController {
LoginViewController *loginView = [[LoginViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginView];
nav.navigationBar.tintColor = [[Session sharedInstance] getThemeColor]; //NAV_BAR_COLOR;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //水平翻转进入
// nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //交叉溶解
// nav.modalTransitionStyle = UIModalTransitionStylePartialCurl; //翻页
// nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical; //从底部滑入
// nav.modalPresentationStyle = UIModalPresentationCurrentContext; //半透明
[self presentModalViewController:nav animated:YES];
/*
[self presentModalViewController:nav animated:NO];
nav.view.alpha = 0.8;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
nav.view.alpha = 1.0;
[UIView commitAnimations];
*/
[nav release];
[loginView release];
}
// 返回 取消 动画
- (void)leftBarButtonItemAction:(id)sender
{
if ([self.navigationController.viewControllers objectAtIndex:0] == self) {
//self.navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //交叉溶解
[self dismissModalViewControllerAnimated:YES];
} else {
// 返回到上一个页面
[self.navigationController popViewControllerAnimated:YES];
// [self.navigationController popToRootViewControllerAnimated:YES]; // 退回的最初的一级
// [self. navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex:2] animated:YES]; // 退回的指定的视图控制器
/*
// 退回的指定的视图控制器
for (UIViewController *controller inself.navigationController.viewControllers) {
if ([controller isKindOfClass:[你要跳转到的Controller class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
*/
}
// 下面只做为参考
- (void)pushAnimationDidStop {
NSLog(@"pushAnimationDidStop...");
}
- (void)pushViewController: (UIViewController*)controller
animatedWithTransition: (UIViewAnimationTransition)transition {
[self.navigationController pushViewController:controller animated:NO];
// TT_FLIP_TRANSITION_DURATION
[UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
- (UIViewController*)popViewControllerAnimatedWithTransition:(UIViewAnimationTransition)transition {
UIViewController* poppedController = [self.navigationController popViewControllerAnimated:NO];
[UIView beginAnimations:nil context:NULL];
// [UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:NO];
[UIView commitAnimations];
return poppedController;
}